Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest fake-timer support #62

Merged
merged 6 commits into from
Jan 26, 2023
Merged

Jest fake-timer support #62

merged 6 commits into from
Jan 26, 2023

Conversation

2xic
Copy link
Contributor

@2xic 2xic commented Nov 7, 2022

Thanks for creating this wonderful runner :)

PR implements the base of jest fake-timer.

src/global-setup.js Outdated Show resolved Hide resolved
@swcm-mnestler
Copy link
Contributor

I'm also interested in this PR - fake timers is the only feature we still use the base jest runner for. Is there anything we can assist with to get this PR merged?

Copy link
Owner

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took so long to land this, thank you! :)

@nicolo-ribaudo nicolo-ribaudo merged commit 9a70f54 into nicolo-ribaudo:main Jan 26, 2023
@@ -20,4 +29,20 @@ globalThis.jest = {
clearAllMocks: jestMock.clearAllMocks.bind(jestMock),
resetAllMocks: jestMock.resetAllMocks.bind(jestMock),
restoreAllMocks: jestMock.restoreAllMocks.bind(jestMock),
useFakeTimers() {
jestTimer.useFakeTimers();
return this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this defined here? should it be return globalThis.jest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this in method of object equals the object?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh well, this is defined if you call jest.useFakeTimers().something. Does it work in Jest if you do (jest.useFakeTimers, 0)().something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this in method of object equals the object?

Hah, TIL 😀

Does it work in Jest if you do (jest.useFakeTimers, 0)().something?

(jest.useFakeTimers , 0) is not a function which seems fair? I get the same doing (document.createElement, 0)() in a browser

Copy link
Contributor

@fisker fisker Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He mean (0, jest.useFakeTimers)().something.

The following won't work either 😄

const {useFakeTimers} = jest
useFakeTimers().something
jest.useFakeTimers.call(null).something
const foo = {useFakeTimers: jest.useFakeTimers}
foo.useFakeTimers().something

@nicolo-ribaudo
Copy link
Owner

Uhh I just noticed I never release this, I'm doing it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants