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

fake timers do not mock AbortSignal.timeout or timers/promises #3088

Closed
6 tasks done
everett1992 opened this issue Mar 28, 2023 · 4 comments
Closed
6 tasks done

fake timers do not mock AbortSignal.timeout or timers/promises #3088

everett1992 opened this issue Mar 28, 2023 · 4 comments
Labels

Comments

@everett1992
Copy link
Contributor

Describe the bug

mock timers do not mock node's timers/promises or AbortSignal.timeout

There is an open issue in sinon fake-timers to implement these.
sinonjs/fake-timers#418

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-5rmugo?file=test/basic.test.ts

describe('with fake timers', () => {
  beforeAll(() => {
    vi.useFakeTimers();
  });

  test('signal should abort after timeout', () => {
    const signal = AbortSignal.timeout(100);
    expect(signal.aborted).toBe(false);
    
    vi.advanceTimersByTime(200);
    
    // This will fail, aborted is still false.
    expect(signal.aborted).toBe(true);
  });
});

System Info

stackblitz

Used Package Manager

npm

Validations

@zbyte64
Copy link

zbyte64 commented Aug 14, 2023

Related: sinonjs/fake-timers#418

@LumaKernel
Copy link

LumaKernel commented Dec 4, 2023

Could mocking module "timers/promises" and "node:timers/promises" builtin solve the problem? Or waiting sinonJS' decision?

@everett1992
Copy link
Contributor Author

I think we're waiting on sinon. In the mean time I've been mocking timers/promises with an implementation that delegates to global setTimeout so it's correctly mocked by useFakeTimers. I'm not sure how accurate my mock is so I won't bother sharing it here.

@sheremet-va
Copy link
Member

sheremet-va commented Feb 16, 2024

I am closing the issue here since Vitest cannot do anything to resolve this unless @sinonjs/fake-timers implement the correct API.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants