全局安装测试工具 jest
npm install jest -g
创建hellow.js功能文件,导出功能函数
//hellow.js
//功能:创建一个变量,变量值是hellow
const hellow='hellow tom';
module.exports= hellow;
功能文件同级目录创建test文件夹,创建index.spec.js文件
//index.spec.js
//测试文件,测试功能文件功能
test('测试 hellow.js',()=>{
const result=require('./../index.js');
//我们断言它的值是hellow tom
expect(result).toBe('hellow tom')
})
执行测试代码
//watch是可选参数,可以在开发时,一直监视
jest hellow --watch