@@ -913,6 +913,32 @@ describe('FakeAsyncTestZoneSpec', () => {
913
913
expect ( d instanceof Date ) . toBe ( true ) ;
914
914
} ) ;
915
915
} ) ;
916
+
917
+ it ( 'should new Date with parameter correctly' , ( ) => {
918
+ fakeAsyncTestZone . run ( ( ) => {
919
+ const d : Date = new Date ( 0 ) ;
920
+ expect ( d . getFullYear ( ) ) . toBeLessThan ( 1971 ) ;
921
+ const d1 : Date = new Date ( 'December 17, 1995 03:24:00' ) ;
922
+ expect ( d1 . getFullYear ( ) ) . toEqual ( 1995 ) ;
923
+ const d2 : Date = new Date ( 1995 , 11 , 17 , 3 , 24 , 0 ) ;
924
+ expect ( d2 . getFullYear ( ) ) . toEqual ( 1995 ) ;
925
+ } ) ;
926
+ } ) ;
927
+
928
+ it ( 'should get Date.UTC() correctly' , ( ) => {
929
+ fakeAsyncTestZone . run ( ( ) => {
930
+ const utcDate = new Date ( Date . UTC ( 96 , 11 , 1 , 0 , 0 , 0 ) ) ;
931
+ expect ( utcDate . getFullYear ( ) ) . toBe ( 1996 ) ;
932
+ } ) ;
933
+ } ) ;
934
+
935
+ it ( 'should call Date.parse() correctly' , ( ) => {
936
+ fakeAsyncTestZone . run ( ( ) => {
937
+ const unixTimeZero = Date . parse ( '01 Jan 1970 00:00:00 GMT' ) ;
938
+ expect ( unixTimeZero ) . toBe ( 0 ) ;
939
+ } ) ;
940
+ } ) ;
941
+
916
942
} ) ;
917
943
918
944
describe (
@@ -932,31 +958,31 @@ describe('FakeAsyncTestZoneSpec', () => {
932
958
} ) ;
933
959
934
960
it ( 'should check date type correctly' , fakeAsync ( ( ) => {
935
- const d : any = new Date ( ) ;
936
- expect ( d instanceof Date ) . toBe ( true ) ;
937
- } ) ) ;
961
+ const d : any = new Date ( ) ;
962
+ expect ( d instanceof Date ) . toBe ( true ) ;
963
+ } ) ) ;
938
964
939
965
it ( 'should mock date correctly' , fakeAsync ( ( ) => {
940
- const baseTime = new Date ( 2013 , 9 , 23 ) ;
941
- jasmine . clock ( ) . mockDate ( baseTime ) ;
942
- const start = Date . now ( ) ;
943
- expect ( start ) . toBe ( baseTime . getTime ( ) ) ;
944
- jasmine . clock ( ) . tick ( 100 ) ;
945
- const end = Date . now ( ) ;
946
- expect ( end - start ) . toBe ( 100 ) ;
947
- expect ( end ) . toBe ( baseTime . getTime ( ) + 100 ) ;
948
- } ) ) ;
966
+ const baseTime = new Date ( 2013 , 9 , 23 ) ;
967
+ jasmine . clock ( ) . mockDate ( baseTime ) ;
968
+ const start = Date . now ( ) ;
969
+ expect ( start ) . toBe ( baseTime . getTime ( ) ) ;
970
+ jasmine . clock ( ) . tick ( 100 ) ;
971
+ const end = Date . now ( ) ;
972
+ expect ( end - start ) . toBe ( 100 ) ;
973
+ expect ( end ) . toBe ( baseTime . getTime ( ) + 100 ) ;
974
+ } ) ) ;
949
975
950
976
it ( 'should handle new Date correctly' , fakeAsync ( ( ) => {
951
- const baseTime = new Date ( 2013 , 9 , 23 ) ;
952
- jasmine . clock ( ) . mockDate ( baseTime ) ;
953
- const start = new Date ( ) ;
954
- expect ( start . getTime ( ) ) . toBe ( baseTime . getTime ( ) ) ;
955
- jasmine . clock ( ) . tick ( 100 ) ;
956
- const end = new Date ( ) ;
957
- expect ( end . getTime ( ) - start . getTime ( ) ) . toBe ( 100 ) ;
958
- expect ( end . getTime ( ) ) . toBe ( baseTime . getTime ( ) + 100 ) ;
959
- } ) ) ;
977
+ const baseTime = new Date ( 2013 , 9 , 23 ) ;
978
+ jasmine . clock ( ) . mockDate ( baseTime ) ;
979
+ const start = new Date ( ) ;
980
+ expect ( start . getTime ( ) ) . toBe ( baseTime . getTime ( ) ) ;
981
+ jasmine . clock ( ) . tick ( 100 ) ;
982
+ const end = new Date ( ) ;
983
+ expect ( end . getTime ( ) - start . getTime ( ) ) . toBe ( 100 ) ;
984
+ expect ( end . getTime ( ) ) . toBe ( baseTime . getTime ( ) + 100 ) ;
985
+ } ) ) ;
960
986
} ) ) ;
961
987
962
988
describe ( 'fakeAsyncTest should patch jasmine.clock' , ifEnvSupports ( supportClock , ( ) => {
@@ -1427,6 +1453,39 @@ const {fakeAsync, tick, discardPeriodicTasks, flush, flushMicrotasks} = fakeAsyn
1427
1453
expect ( zoneInTest1 ) . toBe ( zoneInBeforeEach ) ;
1428
1454
} ) ) ;
1429
1455
} ) ;
1456
+
1457
+ describe ( 'fakeAsync should work with Date' , ( ) => {
1458
+ it ( 'should get date diff correctly' , fakeAsync ( ( ) => {
1459
+ const start = Date . now ( ) ;
1460
+ tick ( 100 ) ;
1461
+ const end = Date . now ( ) ;
1462
+ expect ( end - start ) . toBe ( 100 ) ;
1463
+ } ) ) ;
1464
+
1465
+ it ( 'should check date type correctly' , fakeAsync ( ( ) => {
1466
+ const d : any = new Date ( ) ;
1467
+ expect ( d instanceof Date ) . toBe ( true ) ;
1468
+ } ) ) ;
1469
+
1470
+ it ( 'should new Date with parameter correctly' , fakeAsync ( ( ) => {
1471
+ const d : Date = new Date ( 0 ) ;
1472
+ expect ( d . getFullYear ( ) ) . toBeLessThan ( 1971 ) ;
1473
+ const d1 : Date = new Date ( 'December 17, 1995 03:24:00' ) ;
1474
+ expect ( d1 . getFullYear ( ) ) . toEqual ( 1995 ) ;
1475
+ const d2 : Date = new Date ( 1995 , 11 , 17 , 3 , 24 , 0 ) ;
1476
+ expect ( d2 . getFullYear ( ) ) . toEqual ( 1995 ) ;
1477
+ } ) ) ;
1478
+
1479
+ it ( 'should get Date.UTC() correctly' , fakeAsync ( ( ) => {
1480
+ const utcDate = new Date ( Date . UTC ( 96 , 11 , 1 , 0 , 0 , 0 ) ) ;
1481
+ expect ( utcDate . getFullYear ( ) ) . toBe ( 1996 ) ;
1482
+ } ) ) ;
1483
+
1484
+ it ( 'should call Date.parse() correctly' , fakeAsync ( ( ) => {
1485
+ const unixTimeZero = Date . parse ( '01 Jan 1970 00:00:00 GMT' ) ;
1486
+ expect ( unixTimeZero ) . toBe ( 0 ) ;
1487
+ } ) ) ;
1488
+ } ) ;
1430
1489
} ) ;
1431
1490
1432
1491
describe ( 'ProxyZone' , ( ) => {
0 commit comments