-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
requestAnimationFrame does not invoke callback (v22, jsdom: latest version) #5147
Comments
You can mock Here is a workaround: beforeEach(() => {
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => cb());
});
afterEach(() => {
window.requestAnimationFrame.mockRestore();
}); |
@lukomwro Great solution, you're right, big thanks |
I cannot reproduce this, test('raf', done => {
requestAnimationFrame(() => {
expect(true).toBe(true);
done();
});
}); passes, and switching
|
@SimenB yes, this example will work as expected, but if you will use
so maybe |
That's just async javascript for you. You can open up a separate feature request for |
@SimenB thank you for help, have a nice day :-) |
function myFunction() {
requestAnimationFrame(() => {
console.log('inner');
});
}
myFunction();
console.log('outer'); Logs
There is no way for Jest to know that you have scheduled some async work inside your test and wait for it unless you signal it (either You can also use e.g. this: test('something', () => {
expect.hasAssertions();
requestAnimationFrame(() => {
expect(true).toBe(true);
});
}); Then your test will fail. |
@SimenB yes, you're right, but if you will use jest < 22, you definitely will use |
* Fix test case for new jsdom * use setTimeout as raf in jest jsdom * Fix cancelAnimationFrame * Add comment for jestjs/jest#5147 * longer timeout * fix snap * upgrade antd-tools
* Add the defaultActiveTabKey property for the Card component (close #8789, #8942) * `activeTabKey` should be added * Improve * Fix large tabs font size, close #9509 * docs: Add TreeSelect[dropdownClassName] * Fix passing dropdownClassName to tree-select * build: update remark-parse requirement to ^5.0.0 (#9545) Updates the requirements on [remark-parse](https://github.com/remarkjs/remark) to permit the latest version. - [Release notes](https://github.com/remarkjs/remark/releases) - [Commits](https://github.com/remarkjs/remark/commits/remark@5.0.0) Signed-off-by: dependabot[bot] <support@dependabot.com> * add Tooltip contextMenu doc * Improve Grid and Layout type definition * fix: focus editor (#9548) * Fix test case for new jsdom (#9527) * Fix test case for new jsdom * use setTimeout as raf in jest jsdom * Fix cancelAnimationFrame * Add comment for jestjs/jest#5147 * longer timeout * fix snap * upgrade antd-tools * Update typescript requirement to ~2.7.2 (#9522) Updates the requirements on [typescript](https://github.com/Microsoft/TypeScript) to permit the latest version. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/commits/v2.7.2) Signed-off-by: dependabot[bot] <support@dependabot.com> * Fix a ts error * build: update react-slick requirement to ~0.20.0 (#9543) Updates the requirements on [react-slick](https://github.com/akiran/react-slick) to permit the latest version. - [Changelog](https://github.com/akiran/react-slick/blob/master/CHANGELOG.md) - [Commits](https://github.com/akiran/react-slick/commits) Signed-off-by: dependabot[bot] <support@dependabot.com> * Fix test cases * site: fix intersection-observer polyfill * docs: update recommendation * Fix typo WeexPickerProps -> WeekPickerProps (#9564) * use lodash * Fixed typo on Visualization rules (#9575) Style of a navigation should conform to the its level. should be Style of a navigation should conform to its level. * Improve Radio/Checkbox type definition Close #9574 * Remove AbstractCheckboxChangeEvent, fix TS4029 error See microsoft/TypeScript#9944 * Update index.en-US.md (#9579) * add transitionName from message.config (#9580) * add transitionName from message.config * Update index.en-US.md (#9579) * modify doc * build: update react-virtualized requirement to ~9.18.5 (#9544) Updates the requirements on [react-virtualized](https://github.com/bvaughn/react-virtualized) to permit the latest version. - [Changelog](https://github.com/bvaughn/react-virtualized/blob/master/CHANGELOG.md) - [Commits](https://github.com/bvaughn/react-virtualized/commits/9.18.5) Signed-off-by: dependabot[bot] <support@dependabot.com> * When treeNode is disabled, its switcher is highlight and clickabled (#9539) * When treeNode is disabled, its switcher is highlight and clickabled * rc-tree@1.7.11 * Fix moment require (#9528) Fix #9502 * Update snapshot
Hey, any updates on this? I'm also facing the same issue. I upgraded Jest to v22 and my test using requestAnimationFrame started failing. Is there any way to get around this? Thanks. |
You can mock it if you want |
@SimenB for some reason I can't seem to be able to mock out requestAnimationFrame used inside the raf package.
Any ideas on what's happening here? I know it's not returning my mock because Update: I realized I could just mock the raf module instead. DOH!
This works for me. |
@manatarms JSDOM implements raf, so |
Thanks for the repl @SimenB. For some reason when I put a |
I can replace
But it must go inside (I have used this approach to test |
you can just await a Promise it("raf", async () => {
await new Promise((resolve) =>
requestAnimationFrame(() => {
expect(true).toBe(true);
resolve();
})
)
}) |
Sorry for commenting on this closed issue, but I don't fully understand why |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
A bug
What is the current behavior?
The requestAnimationFrame doesn't invoke callback. Maybe it happened because the jsdom is using setTimeout under the hood, but
useFakeTimers
andrunAllTimers
not helping.If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can
yarn install
andyarn test
.requestAnimationFrame
on your codeWhat is the expected behavior?
requestAnimationFrame should invoke its callback
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
OS: High Sierra
node: 8.9.1
jest: 22.0.3
The text was updated successfully, but these errors were encountered: