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