A Vite-native testing framework. It's fast!
(c) vitest.dev
🐊Putout plugin helps to migrate to latest version of vitest.
npm i @putout/plugin-vitest -D
- ✅ apply-hoisted;
- ✅ convert-jest-to-vitest;
- ✅ v3-apply-options-as-second-argument;
- ✅ v3-apply-browser-instances;
{
"rules": {
"vitest/apply-hoisted": "on",
"vitest/convert-jest-to-vitest": "on",
"vitest/v3-apply-options-as-second-argument": "on",
"vitest/v3-apply-browser-instances": "on"
},
"plugins": ["vitest"]
}All static import statements in ES modules are hoisted to the top of the file, so any code that is defined before the imports will actually be executed after imports are evaluated.
(c) vitest.dev
Checkout in 🐊Putout Editor.
let hello;
let world;
it('hello', () => {
hello.calledWith();
});const hoisted = vi.hoisted({
hello: vi.fn(),
world: vi.fn(),
});
beforeEach(() => {
hello.mockClear();
world.mockClear();
});
it('hello', () => {
hoisted.hello.calledWith();
});Checkout in 🐊Putout Editor.
jest.mock('hello', {
...jest.requireActual('hello'),
abc: jest.fn(),
});vi.mock('hello', async () => ({
...await vi.importActual('hello'),
abc: vi.fn(),
}));Vitest 3.0 prints a warning if you pass down an object as a third argument to test or describe functions. Vitest 4.0 will throw an error if the third argument is an object.
(c) vitest.dev
Checkout in 🐊Putout Editor.
test('validation works', () => {
// ...
}, {
retry: 3,
});test('validation works', {retry: 3}, () => {
// ...
});Both
browser.nameandbrowser.providerOptionswill be removed in Vitest 4. Instead of them, use the newbrowser.instancesoption.(c) vitest.dev
Checkout in 🐊Putout Editor.
export default defineConfig({
test: {
browser: {
name: 'chromium',
providerOptions: {
launch: {
devtools: true,
},
},
},
},
});export default defineConfig({
test: {
browser: {
instances: [{
name: 'chromium',
providerOptions: {
launch: {
devtools: true,
},
},
}],
},
},
});MIT