File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -97,4 +97,23 @@ describe('run with real timers', () => {
97
97
} )
98
98
expect ( global . setTimeout ) . toBe ( fakedSetTimeout )
99
99
} )
100
+
101
+ describe ( 'run with setImmediate and clearImmediate deleted' , ( ) => {
102
+ const setImmediate = global . setImmediate
103
+ const clearImmediate = global . clearImmediate
104
+
105
+ beforeEach ( ( ) => {
106
+ delete global . setImmediate
107
+ delete global . clearImmediate
108
+ } )
109
+
110
+ afterEach ( ( ) => {
111
+ global . setImmediate = setImmediate
112
+ global . clearImmediate = clearImmediate
113
+ } )
114
+
115
+ test ( 'safe check for setImmediate and clearImmediate' , ( ) => {
116
+ expect ( ( ) => runWithRealTimers ( ( ) => { } ) ) . not . toThrow ( )
117
+ } )
118
+ } )
100
119
} )
Original file line number Diff line number Diff line change @@ -16,14 +16,21 @@ function runWithRealTimers(callback) {
16
16
17
17
function runWithJestRealTimers ( callback ) {
18
18
const timerAPI = {
19
- clearImmediate,
20
19
clearInterval,
21
20
clearTimeout,
22
- setImmediate,
23
21
setInterval,
24
22
setTimeout,
25
23
}
26
24
25
+ // For more on why we have the check here,
26
+ // checkout https://github.com/testing-library/dom-testing-library/issues/914
27
+ if ( typeof setImmediate === 'function' ) {
28
+ timerAPI . setImmediate = setImmediate
29
+ }
30
+ if ( typeof clearImmediate === 'function' ) {
31
+ timerAPI . clearImmediate = clearImmediate
32
+ }
33
+
27
34
jest . useRealTimers ( )
28
35
29
36
const callbackReturnValue = callback ( )
You can’t perform that action at this time.
0 commit comments