|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {MomentDateAdapter} from './moment-date-adapter'; |
| 9 | +import {LOCALE_ID} from '@angular/core'; |
10 | 10 | import {async, inject, TestBed} from '@angular/core/testing'; |
11 | | -import {MomentDateModule} from './index'; |
12 | 11 | import {DateAdapter, MAT_DATE_LOCALE} from '@angular/material'; |
13 | | -import {LOCALE_ID} from '@angular/core'; |
14 | 12 | import * as moment from 'moment'; |
| 13 | +import {Moment} from 'moment'; |
| 14 | +import {MomentDateModule} from './index'; |
| 15 | +import {MomentDateAdapter} from './moment-date-adapter'; |
15 | 16 |
|
16 | 17 |
|
17 | 18 | // Month constants for more readable tests. |
18 | 19 | const JAN = 0, FEB = 1, MAR = 2, DEC = 11; |
19 | 20 |
|
20 | 21 |
|
| 22 | +function expectValid(date: Moment | null, valid: boolean) { |
| 23 | + if (date != null) { |
| 24 | + expect(date.isValid()).toBe(valid, |
| 25 | + `expected date to be ${valid ? 'valid' : 'invalid'}, was ${valid ? 'invalid' : 'valid'}`); |
| 26 | + } else { |
| 27 | + fail(`expected ${valid ? 'valid' : 'invalid'} date, was null`); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | + |
21 | 32 | describe('MomentDateAdapter', () => { |
22 | 33 | let adapter: MomentDateAdapter; |
23 | 34 |
|
@@ -309,12 +320,13 @@ describe('MomentDateAdapter', () => { |
309 | 320 | expect(adapter.isDateInstance(d)).toBe(false); |
310 | 321 | }); |
311 | 322 |
|
312 | | - it('should create dates from valid ISO strings', () => { |
313 | | - expect(adapter.fromIso8601('1985-04-12T23:20:50.52Z')).not.toBeNull(); |
314 | | - expect(adapter.fromIso8601('1996-12-19T16:39:57-08:00')).not.toBeNull(); |
315 | | - expect(adapter.fromIso8601('1937-01-01T12:00:27.87+00:20')).not.toBeNull(); |
316 | | - expect(adapter.fromIso8601('1990-13-31T23:59:00Z')).toBeNull(); |
317 | | - expect(adapter.fromIso8601('1/1/2017')).toBeNull(); |
| 323 | + it('should create valid dates from valid ISO strings', () => { |
| 324 | + expectValid(adapter.coerceToDate('1985-04-12T23:20:50.52Z'), true); |
| 325 | + expectValid(adapter.coerceToDate('1996-12-19T16:39:57-08:00'), true); |
| 326 | + expectValid(adapter.coerceToDate('1937-01-01T12:00:27.87+00:20'), true); |
| 327 | + expectValid(adapter.coerceToDate('1990-13-31T23:59:00Z'), false); |
| 328 | + expectValid(adapter.coerceToDate('1/1/2017'), false); |
| 329 | + expect(adapter.coerceToDate('')).toBeNull(); |
318 | 330 | }); |
319 | 331 |
|
320 | 332 | it('setLocale should not modify global moment locale', () => { |
|
0 commit comments