1 引入jest
2 在package.json的script中配置
"scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint", "test": "jest --watchAll", "coverage":"jest --coverage" },
新建一个文件 sum.js
function sum(a, b) { return a + b; } module.exports = sum;
新建一个sum.test.js
const sum = require('./sum'); test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); }); test("测试",()=>{ const a = {num:'ui'} expect(a).toBe({num:'ui'}) })