1- import { NativeDateAdapter } from './native-date-adapter' ;
1+ import { TestBed , async , inject } from '@angular/core/testing' ;
2+ import { LOCALE_ID } from '@angular/core' ;
3+ import { NativeDateAdapter , NativeDateModule , DateAdapter } from './index' ;
24import { Platform } from '../platform/index' ;
35import { DEC , FEB , JAN , MAR } from '../testing/month-constants' ;
46
57const SUPPORTS_INTL = typeof Intl != 'undefined' ;
68
79describe ( 'NativeDateAdapter' , ( ) => {
8- let adapter ;
9- let platform ;
10+ const platform = new Platform ( ) ;
11+ let adapter : NativeDateAdapter ;
1012
11- beforeEach ( ( ) => {
12- adapter = new NativeDateAdapter ( ) ;
13- platform = new Platform ( ) ;
14- } ) ;
13+ beforeEach ( async ( ( ) => {
14+ TestBed . configureTestingModule ( {
15+ imports : [ NativeDateModule ]
16+ } ) . compileComponents ( ) ;
17+ } ) ) ;
18+
19+ beforeEach ( inject ( [ DateAdapter ] , ( d : NativeDateAdapter ) => {
20+ adapter = d ;
21+ } ) ) ;
1522
1623 it ( 'should get year' , ( ) => {
1724 expect ( adapter . getYear ( new Date ( 2017 , JAN , 1 ) ) ) . toBe ( 2017 ) ;
@@ -195,9 +202,9 @@ describe('NativeDateAdapter', () => {
195202
196203 it ( 'should format' , ( ) => {
197204 if ( SUPPORTS_INTL ) {
198- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) ) ) . toEqual ( '1/1/2017' ) ;
205+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '1/1/2017' ) ;
199206 } else {
200- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) ) ) . toEqual ( 'Sun Jan 01 2017' ) ;
207+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( 'Sun Jan 01 2017' ) ;
201208 }
202209 } ) ;
203210
@@ -222,12 +229,12 @@ describe('NativeDateAdapter', () => {
222229 if ( SUPPORTS_INTL ) {
223230 // Edge & IE use a different format in Japanese.
224231 if ( platform . EDGE || platform . TRIDENT ) {
225- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) ) ) . toEqual ( '2017年1月1日' ) ;
232+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '2017年1月1日' ) ;
226233 } else {
227- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) ) ) . toEqual ( '2017/1/1' ) ;
234+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( '2017/1/1' ) ;
228235 }
229236 } else {
230- expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) ) ) . toEqual ( 'Sun Jan 01 2017' ) ;
237+ expect ( adapter . format ( new Date ( 2017 , JAN , 1 ) , { } ) ) . toEqual ( 'Sun Jan 01 2017' ) ;
231238 }
232239 } ) ;
233240
@@ -290,3 +297,28 @@ describe('NativeDateAdapter', () => {
290297 . toEqual ( new Date ( 2018 , FEB , 1 ) ) ;
291298 } ) ;
292299} ) ;
300+
301+
302+ describe ( 'NativeDateAdapter with LOCALE_ID override' , ( ) => {
303+ let adapter : NativeDateAdapter ;
304+
305+ beforeEach ( async ( ( ) => {
306+ TestBed . configureTestingModule ( {
307+ imports : [ NativeDateModule ] ,
308+ providers : [ { provide : LOCALE_ID , useValue : 'da-DK' } ]
309+ } ) . compileComponents ( ) ;
310+ } ) ) ;
311+
312+ beforeEach ( inject ( [ DateAdapter ] , ( d : NativeDateAdapter ) => {
313+ adapter = d ;
314+ } ) ) ;
315+
316+ it ( 'should take the default locale id from the LOCALE_ID injection token' , ( ) => {
317+ const expectedValue = SUPPORTS_INTL ?
318+ [ 'søndag' , 'mandag' , 'tirsdag' , 'onsdag' , 'torsdag' , 'fredag' , 'lørdag' ] :
319+ [ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ] ;
320+
321+ expect ( adapter . getDayOfWeekNames ( 'long' ) ) . toEqual ( expectedValue ) ;
322+ } ) ;
323+
324+ } ) ;
0 commit comments