首页 > 编程语言 > 详细

[Jest] Test JavaScript with Jest

时间:2016-09-03 06:23:17      阅读:278      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/Answer1215/p/5836141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!