Skip to content

advanceTimersToNextFrame doesn't advance timers immediately #6493

@kaisermann

Description

@kaisermann

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions