Skip to content

Commit 2781ebc

Browse files
committed
tests: properly restoration of global variables
Make sure that if the test breaks, it would not break other tests either by properly restoring those global variables in an afterEach call.
1 parent 4580d71 commit 2781ebc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/__tests__/helpers.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,22 @@ describe('run with real timers', () => {
9898
expect(global.setTimeout).toBe(fakedSetTimeout)
9999
})
100100

101-
test('safe check for setImmediate and clearImmediate', () => {
102-
const setImeediate = global.setImmediate
101+
describe('run with setImmediate and clearImmediate deleted', () => {
102+
const setImmediate = global.setImmediate
103103
const clearImmediate = global.clearImmediate
104-
delete global.setImmediate
105-
delete global.clearImmediate
106104

107-
expect(() => runWithRealTimers(() => {})).not.toThrow()
105+
beforeEach(() => {
106+
delete global.setImmediate
107+
delete global.clearImmediate
108+
})
109+
110+
afterEach(() => {
111+
global.setImmediate = setImmediate
112+
global.clearImmediate = clearImmediate
113+
})
108114

109-
global.setImmediate = setImeediate
110-
global.clearImmediate = clearImmediate
115+
test('safe check for setImmediate and clearImmediate', () => {
116+
expect(() => runWithRealTimers(() => {})).not.toThrow()
117+
})
111118
})
112119
})

0 commit comments

Comments
 (0)