码迷,mamicode.com
首页 > 编程语言 > 详细

[Jest] Test JavaScript with Jest

时间:2016-09-03 06:24:57      阅读:239      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!