xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Vitest All In One

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://vitest.dev/guide/

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

image

https://stackblitz.com/edit/vitest-dev-vitest-rm2j5o?initialPath=vitest/

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

https://vueschool.io/lessons/how-to-install-vitest

refs

https://stackoverflow.com/questions/77237009/running-vitest-on-compiled-javascript



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-10-08 22:48  xgqfrms  阅读(4)  评论(2编辑  收藏  举报