简单使用Jest-JavaScript测试工具

Jest是Facebook开源的一套JavaScript测试框架 安装 在项目中安装 yarn add –dev jest或者npm install –save-dev jest 全局安装 yarn global add jest hello.js module.exports = function(){ return "hello world" } hello.test.js const hello = require('../hello') it('should ', () => { expect(hello()).toBe('hello world') }) package.json { "scripts": { "test": "jest" } } 执行测试 yarn test或者npm run test exspect() //运行结果 toBe() //期待的结果 not.toBe() //判断不等 toBeNull() //判断是否为NULL toBeUndefined() //判断是否为undefined toBeDefined() //判断是否为undefined取反 toBeTruthy() //判断结果为true toBeFalsy() //判断结果为false toBeGreaterThan(5) //判断结果是否大于5 toBeLessThan(5) //判断结果是否小于5 toBeGreaterThanOrEqual(6) //判断结果是否大于等于6...

2021-09-06 · 1 min · Me