Comments (3)
queueMicrotask
is not mocked by default, so I think you would need to add it to vi.useFakeTimers({ toFake: ['queueMicrotask'] })
https://vitest.dev/api/vi.html#vi-usefaketimers
from vitest.
Does this work?
import { vi, expect, test } from 'vitest'
test('Allow to encode and decode data', async () => {
vi.useFakeTimers();
const mock = vi.fn();
queueMicrotask(() => {
mock(1);
});
await vi.runAllTimersAsync()
expect(mock).toHaveBeenCalledWith(1);
});
from vitest.
Minimal reproduction works when toFake
is defined as instructed above.
https://stackblitz.com/edit/vitest-dev-vitest-nvum37?file=test%2Fbasic.test.ts.
import { vi, expect, test } from 'vitest';
test('Allow to encode and decode data', () => {
- vi.useFakeTimers();
+ vi.useFakeTimers({ toFake: ['queueMicrotask'] });
const mock = vi.fn();
queueMicrotask(() => {
mock(1);
});
vi.advanceTimersToNextTimer();
vi.advanceTimersByTime(2000);
expect(mock).toHaveBeenCalledWith(1);
});
from vitest.
Related Issues (20)
- `RangeError: Maximum call stack size exceeded` when `toMatchObject` with array circular references HOT 1
- Vitest workspace - config from packages leaking into other packages HOT 4
- Threshold on a Glob Pattern does not show an error message HOT 3
- `bun test` should drop-in replace `vi.useFakeTimers` + `vi.setSystemTime` + `vi.useRealTimers` using vitest like it does with jest globals HOT 1
- Vitest browser hangs for more than 127 test files HOT 1
- Vitest not working with bun
- bun test not working HOT 1
- When upgrading from 1.4.0 to 1.5.0, an error related to CommonJS modules appears. HOT 4
- Update the new API to allow some suites to be `sequential` and others to be `shuffle` HOT 1
- V8 coverage fails, looks like it loosing actual node HOT 1
- Vitest hangs when `describe` is exported as `then` HOT 1
- Inconsistent `import.meta.env.SSR` (`false` on `vmThreads` pool and `true` on other pools)
- Can not connect @vitest/ui HOT 3
- Module transform causes errors HOT 2
- Absolute file path for the filter pattern leads to abnormal behaviour
- browser mode domoperation is invisible HOT 1
- Debugger stops at at end of file when "stepping into" HOT 2
- Incompatible with with Comlink Workers HOT 3
- Fails to run tests with remote modules HOT 2
- ES module import fails with v1.5.0 (but works up to v1.4.0) HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vitest.