@@ -913,17 +913,45 @@ 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 (
919
- 'fakeAsyncTest should work without jasmine.clock' ,
945
+ 'fakeAsyncTest should work without patch jasmine.clock' ,
920
946
ifEnvSupports (
921
947
( ) => {
922
948
return ! supportClock ( ) && supportNode ( ) ;
923
949
} ,
924
950
( ) => {
925
951
const fakeAsync = ( Zone as any ) [ Zone . __symbol__ ( 'fakeAsyncTest' ) ] . fakeAsync ;
952
+ let spy : any ;
926
953
beforeEach ( ( ) => {
954
+ spy = jasmine . createSpy ( 'timer' ) ;
927
955
jasmine . clock ( ) . install ( ) ;
928
956
} ) ;
929
957
@@ -932,11 +960,44 @@ describe('FakeAsyncTestZoneSpec', () => {
932
960
} ) ;
933
961
934
962
it ( 'should check date type correctly' , fakeAsync ( ( ) => {
963
+ const d : any = new Date ( ) ;
964
+ expect ( d instanceof Date ) . toBe ( true ) ;
965
+ } ) ) ;
966
+
967
+ it ( 'should check date type correctly without fakeAsync' , ( ) => {
935
968
const d : any = new Date ( ) ;
936
969
expect ( d instanceof Date ) . toBe ( true ) ;
937
- } ) ) ;
970
+ } ) ;
971
+
972
+ it ( 'should tick correctly' , fakeAsync ( ( ) => {
973
+ jasmine . clock ( ) . mockDate ( ) ;
974
+ const start = Date . now ( ) ;
975
+ jasmine . clock ( ) . tick ( 100 ) ;
976
+ const end = Date . now ( ) ;
977
+ expect ( end - start ) . toBe ( 100 ) ;
978
+ } ) ) ;
979
+
980
+ it ( 'should tick correctly without fakeAsync' , ( ) => {
981
+ jasmine . clock ( ) . mockDate ( ) ;
982
+ const start = Date . now ( ) ;
983
+ jasmine . clock ( ) . tick ( 100 ) ;
984
+ const end = Date . now ( ) ;
985
+ expect ( end - start ) . toBe ( 100 ) ;
986
+ } ) ;
938
987
939
988
it ( 'should mock date correctly' , fakeAsync ( ( ) => {
989
+ const baseTime = new Date ( 2013 , 9 , 23 ) ;
990
+ jasmine . clock ( ) . mockDate ( baseTime ) ;
991
+ const start = Date . now ( ) ;
992
+ expect ( start ) . toBe ( baseTime . getTime ( ) ) ;
993
+ jasmine . clock ( ) . tick ( 100 ) ;
994
+ const end = Date . now ( ) ;
995
+ expect ( end - start ) . toBe ( 100 ) ;
996
+ expect ( end ) . toBe ( baseTime . getTime ( ) + 100 ) ;
997
+ expect ( new Date ( ) . getFullYear ( ) ) . toEqual ( 2013 ) ;
998
+ } ) ) ;
999
+
1000
+ it ( 'should mock date correctly without fakeAsync' , ( ) => {
940
1001
const baseTime = new Date ( 2013 , 9 , 23 ) ;
941
1002
jasmine . clock ( ) . mockDate ( baseTime ) ;
942
1003
const start = Date . now ( ) ;
@@ -945,9 +1006,21 @@ describe('FakeAsyncTestZoneSpec', () => {
945
1006
const end = Date . now ( ) ;
946
1007
expect ( end - start ) . toBe ( 100 ) ;
947
1008
expect ( end ) . toBe ( baseTime . getTime ( ) + 100 ) ;
948
- } ) ) ;
1009
+ expect ( new Date ( ) . getFullYear ( ) ) . toEqual ( 2013 ) ;
1010
+ } ) ;
949
1011
950
1012
it ( 'should handle new Date correctly' , fakeAsync ( ( ) => {
1013
+ const baseTime = new Date ( 2013 , 9 , 23 ) ;
1014
+ jasmine . clock ( ) . mockDate ( baseTime ) ;
1015
+ const start = new Date ( ) ;
1016
+ expect ( start . getTime ( ) ) . toBe ( baseTime . getTime ( ) ) ;
1017
+ jasmine . clock ( ) . tick ( 100 ) ;
1018
+ const end = new Date ( ) ;
1019
+ expect ( end . getTime ( ) - start . getTime ( ) ) . toBe ( 100 ) ;
1020
+ expect ( end . getTime ( ) ) . toBe ( baseTime . getTime ( ) + 100 ) ;
1021
+ } ) ) ;
1022
+
1023
+ it ( 'should handle new Date correctly without fakeAsync' , ( ) => {
951
1024
const baseTime = new Date ( 2013 , 9 , 23 ) ;
952
1025
jasmine . clock ( ) . mockDate ( baseTime ) ;
953
1026
const start = new Date ( ) ;
@@ -956,11 +1029,27 @@ describe('FakeAsyncTestZoneSpec', () => {
956
1029
const end = new Date ( ) ;
957
1030
expect ( end . getTime ( ) - start . getTime ( ) ) . toBe ( 100 ) ;
958
1031
expect ( end . getTime ( ) ) . toBe ( baseTime . getTime ( ) + 100 ) ;
959
- } ) ) ;
1032
+ } ) ;
1033
+
1034
+ it ( 'should handle setTimeout correctly' , fakeAsync ( ( ) => {
1035
+ setTimeout ( spy , 100 ) ;
1036
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
1037
+ jasmine . clock ( ) . tick ( 100 ) ;
1038
+ expect ( spy ) . toHaveBeenCalled ( ) ;
1039
+ } ) ) ;
1040
+
1041
+ it ( 'should handle setTimeout correctly without fakeAsync' , ( ) => {
1042
+ setTimeout ( spy , 100 ) ;
1043
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
1044
+ jasmine . clock ( ) . tick ( 100 ) ;
1045
+ expect ( spy ) . toHaveBeenCalled ( ) ;
1046
+ } ) ;
960
1047
} ) ) ;
961
1048
962
1049
describe ( 'fakeAsyncTest should patch jasmine.clock' , ifEnvSupports ( supportClock , ( ) => {
1050
+ let spy : any ;
963
1051
beforeEach ( ( ) => {
1052
+ spy = jasmine . createSpy ( 'timer' ) ;
964
1053
jasmine . clock ( ) . install ( ) ;
965
1054
} ) ;
966
1055
@@ -980,6 +1069,13 @@ describe('FakeAsyncTestZoneSpec', () => {
980
1069
expect ( end - start ) . toBe ( 100 ) ;
981
1070
} ) ;
982
1071
1072
+ it ( 'should tick correctly' , ( ) => {
1073
+ const start = Date . now ( ) ;
1074
+ jasmine . clock ( ) . tick ( 100 ) ;
1075
+ const end = Date . now ( ) ;
1076
+ expect ( end - start ) . toBe ( 100 ) ;
1077
+ } ) ;
1078
+
983
1079
it ( 'should mock date correctly' , ( ) => {
984
1080
const baseTime = new Date ( 2013 , 9 , 23 ) ;
985
1081
jasmine . clock ( ) . mockDate ( baseTime ) ;
@@ -1001,6 +1097,13 @@ describe('FakeAsyncTestZoneSpec', () => {
1001
1097
expect ( end . getTime ( ) - start . getTime ( ) ) . toBe ( 100 ) ;
1002
1098
expect ( end . getTime ( ) ) . toBe ( baseTime . getTime ( ) + 100 ) ;
1003
1099
} ) ;
1100
+
1101
+ it ( 'should handle setTimeout correctly' , ( ) => {
1102
+ setTimeout ( spy , 100 ) ;
1103
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
1104
+ jasmine . clock ( ) . tick ( 100 ) ;
1105
+ expect ( spy ) . toHaveBeenCalled ( ) ;
1106
+ } ) ;
1004
1107
} ) ) ;
1005
1108
1006
1109
describe ( 'fakeAsyncTest should patch rxjs scheduler' , ifEnvSupports ( supportClock , ( ) => {
@@ -1427,6 +1530,39 @@ const {fakeAsync, tick, discardPeriodicTasks, flush, flushMicrotasks} = fakeAsyn
1427
1530
expect ( zoneInTest1 ) . toBe ( zoneInBeforeEach ) ;
1428
1531
} ) ) ;
1429
1532
} ) ;
1533
+
1534
+ describe ( 'fakeAsync should work with Date' , ( ) => {
1535
+ it ( 'should get date diff correctly' , fakeAsync ( ( ) => {
1536
+ const start = Date . now ( ) ;
1537
+ tick ( 100 ) ;
1538
+ const end = Date . now ( ) ;
1539
+ expect ( end - start ) . toBe ( 100 ) ;
1540
+ } ) ) ;
1541
+
1542
+ it ( 'should check date type correctly' , fakeAsync ( ( ) => {
1543
+ const d : any = new Date ( ) ;
1544
+ expect ( d instanceof Date ) . toBe ( true ) ;
1545
+ } ) ) ;
1546
+
1547
+ it ( 'should new Date with parameter correctly' , fakeAsync ( ( ) => {
1548
+ const d : Date = new Date ( 0 ) ;
1549
+ expect ( d . getFullYear ( ) ) . toBeLessThan ( 1971 ) ;
1550
+ const d1 : Date = new Date ( 'December 17, 1995 03:24:00' ) ;
1551
+ expect ( d1 . getFullYear ( ) ) . toEqual ( 1995 ) ;
1552
+ const d2 : Date = new Date ( 1995 , 11 , 17 , 3 , 24 , 0 ) ;
1553
+ expect ( d2 . getFullYear ( ) ) . toEqual ( 1995 ) ;
1554
+ } ) ) ;
1555
+
1556
+ it ( 'should get Date.UTC() correctly' , fakeAsync ( ( ) => {
1557
+ const utcDate = new Date ( Date . UTC ( 96 , 11 , 1 , 0 , 0 , 0 ) ) ;
1558
+ expect ( utcDate . getFullYear ( ) ) . toBe ( 1996 ) ;
1559
+ } ) ) ;
1560
+
1561
+ it ( 'should call Date.parse() correctly' , fakeAsync ( ( ) => {
1562
+ const unixTimeZero = Date . parse ( '01 Jan 1970 00:00:00 GMT' ) ;
1563
+ expect ( unixTimeZero ) . toBe ( 0 ) ;
1564
+ } ) ) ;
1565
+ } ) ;
1430
1566
} ) ;
1431
1567
1432
1568
describe ( 'ProxyZone' , ( ) => {
0 commit comments