Skip to content

Commit

Permalink
Explicitly return jest in timer mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 6, 2023
1 parent 1e56a64 commit 3c197c3
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,40 @@ const jestTimer = new ModernFakeTimers({
global: globalThis,
});

globalThis.expect = expect;
globalThis.test = circus.test;
globalThis.it = circus.it;
globalThis.xit = globalThis.xtest = circus.test.skip;
globalThis.fit = circus.test.only;
globalThis.describe = circus.describe;
globalThis.xdescribe = circus.describe.skip;
globalThis.fdescribe = circus.describe.only;
globalThis.beforeAll = circus.beforeAll;
globalThis.afterAll = circus.afterAll;
globalThis.beforeEach = circus.beforeEach;
globalThis.afterEach = circus.afterEach;
globalThis.jest = {
const jest = {
fn: jestMock.fn.bind(jestMock),
spyOn: jestMock.spyOn.bind(jestMock),
clearAllMocks: jestMock.clearAllMocks.bind(jestMock),
resetAllMocks: jestMock.resetAllMocks.bind(jestMock),
restoreAllMocks: jestMock.restoreAllMocks.bind(jestMock),
useFakeTimers() {
jestTimer.useFakeTimers();
return this;
return jest;
},
setSystemTime(time) {
jestTimer.setSystemTime(time);
return this;
return jest;
},
advanceTimersByTime(ms) {
jestTimer.advanceTimersByTime(ms);
return this;
return jest;
},
useRealTimers() {
jestTimer.useRealTimers();
return this;
return jest;
},
};

globalThis.expect = expect;
globalThis.test = circus.test;
globalThis.it = circus.it;
globalThis.xit = globalThis.xtest = circus.test.skip;
globalThis.fit = circus.test.only;
globalThis.describe = circus.describe;
globalThis.xdescribe = circus.describe.skip;
globalThis.fdescribe = circus.describe.only;
globalThis.beforeAll = circus.beforeAll;
globalThis.afterAll = circus.afterAll;
globalThis.beforeEach = circus.beforeEach;
globalThis.afterEach = circus.afterEach;
globalThis.jest = jest;

0 comments on commit 3c197c3

Please sign in to comment.