首页 > 代码库 > [Jest] Test JavaScript with Jest
[Jest] Test JavaScript with Jest
Let‘s learn how to unit test your JavaScript with Jest, a JavaScript unit testing framework from Facebook. We‘ll install and optimize Jest for this project and see how quick and easy it is to get things going with Jest.
Install:
npm i jest-cli --save-dev
sum.js:
var R = require(‘ramda‘)module.exports = sum;function sum(ary){ return R.sum(ary);}
sum.test.js:
const sum = require(‘./sum‘)test(‘adds 1 + 2 to equal 3‘, () => { expect(sum([1,2])).toBe(3)})
Package.json:
Because jest simulate the broswer, so you are able to access ‘window‘ object. But it is really not necessary for Node app.
So, you can config it in package.json:
"jest": { "testEnvironment": "node" },
[Jest] Test JavaScript with Jest
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。