Vitest All In One
Vite + Test
Next Generation Testing Framework.
A Vite-native testing framework.
# Vitest requires Vite >=v3.0.0 and Node >=v14.18
$ npm i -D vitest
https://github.com/vitest-dev/vitest
https://vitest.dev/guide/why.html
Mock Functions
mock
&spyOn
// vi ❓vim
import { vi } from 'vitest'
const fn = vi.fn()
fn('hello world')
fn.mock.calls[0] === ['hello world']
const market = {
getApples: () => 100
}
const getApplesSpy = vi.spyOn(market, 'getApples')
market.getApples()
getApplesSpy.mock.calls.length === 1
https://vitest.dev/api/mock.html
demos
https://stackblitz.com/edit/vitest-dev-vitest-rm2j5o?initialPath=vitest/