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

advanceTimersToNextFrame doesn't advance timers immediately #6493

Closed
6 tasks done
kaisermann opened this issue Sep 13, 2024 · 3 comments
Closed
6 tasks done

advanceTimersToNextFrame doesn't advance timers immediately #6493

kaisermann opened this issue Sep 13, 2024 · 3 comments

Comments

@kaisermann
Copy link

Describe the bug

The solution for #6346, implemented on #6347 doesn't seem to work as described in the original issue.

Reproduction link is found below, but the code is:

import { vi, expect, test } from 'vitest';

vi.useFakeTimers();

test('works', () => {
  let frameRendered = false;

  window.requestAnimationFrame(() => {
    frameRendered = true;
  });

  vi.advanceTimersToNextFrame();

  expect(frameRendered).toBe(true); // throws, `frameRendered` is false
});

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-zd3lj1?file=test%2Fbasic.test.ts

System Info

System:
  OS: macOS 14.1.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 113.53 MB / 32.00 GB
  Shell: 3.7.1 - /opt/homebrew/bin/fish
Binaries:
  Node: 18.17.1 - ~/.volta/tools/image/node/18.17.1/bin/node
  Yarn: 4.2.2 - ~/.volta/tools/image/yarn/4.2.2/bin/yarn
  npm: 9.6.7 - ~/.volta/tools/image/node/18.17.1/bin/npm
Browsers:
  Chrome: 128.0.6613.138
  Edge: 128.0.2739.79
  Safari: 17.1
NPM Packages:
  vitest: 2.1.0

Used Package Manager

yarn

Validations

@AriPerkkio
Copy link
Member

Does this help?

- vi.useFakeTimers();
+ vi.useFakeTimers({ toFake: ['requestAnimationFrame', 'setTimeout'] });

@kaisermann
Copy link
Author

@AriPerkkio it does! I was sure I got a Typescript error when I tried to do that. This can be closed then as the defaults are documented on the website and in the JSDoc.

Though, we could change the Tip content in the docs to include all the non-default APIs.

@sheremet-va
Copy link
Member

This can be closed then as the defaults are documented on the website and in the JSDoc.

Just a note but this will be changed in the next major: #6288

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

No branches or pull requests

3 participants