@@ -1005,6 +1005,25 @@ describe("Env integration", function() {
1005
1005
1006
1006
describe ( "with a mock clock" , function ( ) {
1007
1007
var realSetTimeout ;
1008
+ function createMockedEnv ( ) {
1009
+ // explicitly pass in timing functions so we can make sure that clear stack always works
1010
+ // no matter how long the suite in the spec is
1011
+ return new jasmineUnderTest . Env ( { global : {
1012
+ setTimeout : function ( cb , t ) {
1013
+ var stack = jasmine . util . errorWithStack ( ) . stack ;
1014
+ if ( stack . indexOf ( 'ClearStack' ) >= 0 ) {
1015
+ realSetTimeout ( cb , t ) ;
1016
+ } else {
1017
+ setTimeout ( cb , t ) ;
1018
+ }
1019
+ } ,
1020
+ clearTimeout : clearTimeout ,
1021
+ setInterval : setInterval ,
1022
+ clearInterval : clearInterval ,
1023
+ setImmediate : function ( cb ) { realSetTimeout ( cb , 0 ) ; }
1024
+ } } ) ;
1025
+ }
1026
+
1008
1027
beforeEach ( function ( ) {
1009
1028
this . originalTimeout = jasmineUnderTest . DEFAULT_TIMEOUT_INTERVAL ;
1010
1029
realSetTimeout = setTimeout ;
@@ -1019,7 +1038,7 @@ describe("Env integration", function() {
1019
1038
} ) ;
1020
1039
1021
1040
it ( "should wait a default interval before failing specs that haven't called done yet" , function ( done ) {
1022
- var env = new jasmineUnderTest . Env ( ) ,
1041
+ var env = createMockedEnv ( ) ,
1023
1042
reporter = jasmine . createSpyObj ( 'fakeReporter' , [ "specDone" , "jasmineDone" ] ) ;
1024
1043
1025
1044
reporter . specDone . and . callFake ( function ( result ) {
@@ -1048,7 +1067,7 @@ describe("Env integration", function() {
1048
1067
} ) ;
1049
1068
1050
1069
it ( "should not use the mock clock for asynchronous timeouts" , function ( done ) {
1051
- var env = new jasmineUnderTest . Env ( ) ,
1070
+ var env = createMockedEnv ( ) ,
1052
1071
reporter = jasmine . createSpyObj ( 'fakeReporter' , [ "specDone" , "jasmineDone" ] ) ,
1053
1072
clock = env . clock ;
1054
1073
@@ -1086,23 +1105,13 @@ describe("Env integration", function() {
1086
1105
} ) ;
1087
1106
1088
1107
it ( 'should wait a custom interval before reporting async functions that fail to call done' , function ( done ) {
1089
- var env = new jasmineUnderTest . Env ( ) ,
1108
+ var env = createMockedEnv ( ) ,
1090
1109
reporter = jasmine . createSpyObj ( 'fakeReport' , [ 'jasmineDone' , 'suiteDone' , 'specDone' ] ) ,
1091
1110
timeoutFailure = ( / ^ E r r o r : T i m e o u t - A s y n c c a l l b a c k w a s n o t i n v o k e d w i t h i n t i m e o u t s p e c i f i e d b y j a s m i n e \. D E F A U L T _ T I M E O U T _ I N T E R V A L \. / ) ;
1092
1111
1093
- reporter . specDone . and . callFake ( function ( r ) {
1094
- realSetTimeout ( function ( ) {
1095
- jasmine . clock ( ) . tick ( 1 ) ;
1096
- } , 0 ) ;
1097
- } ) ;
1098
-
1099
- reporter . suiteDone . and . callFake ( function ( r ) {
1100
- realSetTimeout ( function ( ) {
1101
- jasmine . clock ( ) . tick ( 1 ) ;
1102
- } , 0 ) ;
1103
- } ) ;
1104
1112
1105
- reporter . jasmineDone . and . callFake ( function ( ) {
1113
+ reporter . jasmineDone . and . callFake ( function ( r ) {
1114
+ expect ( r . failedExpectations ) . toEqual ( [ ] ) ;
1106
1115
expect ( reporter . suiteDone ) . toHaveFailedExpectationsForRunnable ( 'suite beforeAll' , [ timeoutFailure ] ) ;
1107
1116
expect ( reporter . suiteDone ) . toHaveFailedExpectationsForRunnable ( 'suite afterAll' , [ timeoutFailure ] ) ;
1108
1117
expect ( reporter . specDone ) . toHaveFailedExpectationsForRunnable ( 'suite beforeEach times out' , [ timeoutFailure ] ) ;
0 commit comments