[React Testing] Setting up dependencies && Running tests
To write tests for our React code, we need to first install some libraries for running tests and writing assertions. In this lesson we walk through setting up Mocha as our test runner and expect
as our assertion library. We will also set up some React and JSX specific test tools (React Test Utils) to make writing our tests easier.
NOTE: There are many alternatives to Mocha, expect, and the other test tools we use in this course. Although we use these specific tools and libraries, the testing principles apply to all other tools.
package.json:
{
"name": "react-testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"expect": "1.13.4",
"mocha": "2.3.4",
"react-addons-test-utils": "0.14.5"
},
"dependencies": {
"react": "0.14.5",
"react-dom": "0.14.5"
}
}
we walk through how to setup our tests and run them. We write a quick empty first test and assertion, so we can run the tests. Using Mocha, we can do this manually each time with the Mocha CLI. We can also automate this using task runner features from tools like Grunt, Gulp, Webpack, or npm scripts. In this course, we will use the common npm test
script setup to run our tests. We will also use the Babel compiler to write our tests with modern JavaScript syntax.
import expect from 'expect'; describe('empty', ()=>{ it('should work', ()=>{
expect(true ).toEqual(true);
});
});
packjson.js: Install babel also
{
"name": "react-testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha ./src/**/*.spec.js --compilers js:babel-core/register",
"test:watch": "npm test -- --watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "6.1.4",
"babel-loader": "6.1.0",
"babel-preset-es2015": "6.1.4",
"babel-preset-react": "6.1.4",
"babel-preset-stage-2": "6.1.2",
"expect": "1.12.2",
"mocha": "2.3.3",
"react-addons-test-utils": "0.14.3",
},
"dependencies": {
"react": "0.14.3",
"react-dom": "0.14.3"
}
}
.babelrc
{
"presets": ["react", "stage-2", "es2015"]
}
[React Testing] Setting up dependencies && Running tests的更多相关文章
- 如何使用TDD和React Testing Library构建健壮的React应用程序
如何使用TDD和React Testing Library构建健壮的React应用程序 当我开始学习React时,我努力的一件事就是以一种既有用又直观的方式来测试我的web应用程序. 每次我想测试它时 ...
- React Testing All in One
React Testing All in One React 测试 https://reactjs.org/docs/testing.html jest 26.4 https://jestjs.io/ ...
- appium(3)-Running Tests
Running Tests Preparing your app for test (iOS) Test apps run on the simulator have to be compiled ...
- [Git] Automatically running tests before commits with ghooks
Wouldn't it be nice if everyone ran the tests before committing code? With ghooks, you can automatic ...
- [React Testing] JSX error diffs -- expect-jsx library
When writing React component tests, it can be hard to decipher the error diffs of broken tests, sinc ...
- [React Testing] Intro to Shallow Rendering
In this lesson, we walk through how to use one of React's Test Utilities (from thereact-addons-test- ...
- Running tests on PyCharm using Robot Framework
问题: I started using PyCharm with the robot framework, but i'm facing an issue. how can i run my test ...
- [React Testing] Redux Reducers
Sometimes we want to test our Redux reducers to make sure they work as expected. In this lesson we w ...
- [React Testing] The Redux Store - Multiple Actions
When using Redux, we can test that our application state changes are working by testing that dispatc ...
随机推荐
- JQuery 代码
http://baike.baidu.com/view/136475.htmhttp://www.cnblogs.com/gleamy_ming/archive/2009/04/29/1446492. ...
- JavaScript中的內定物件與函式: arguments, callee, caller, this, apply(), call()
arguments, caller, callee, this都是用在函式(function)內的特殊內定物件.而apply()及call()則是用來呼叫函式的不同作法. arguments可用來取得 ...
- 命令passwd报错因inode节点处理记录
命令passwd报错因inode节点处理记录故障现象:1.修改密码时报错 passwd: Authentication token manipulation error2.添加用户报错:unable ...
- phpcms v9联动菜单实现筛选
<!--初始化init--> {php $theurl = "index.php?m=content&c=index&a=lists&catid=$cat ...
- switch case加条件语句(非等值) php
<?php $s_level=rand(1,6); echo $s_level.'<br/>'; switch(true){ case $s_level<3 : echo 'l ...
- JS中typeof与instanceof的区别 (2010-05-26 10:47:40
JavaScript 中 typeof 和 instanceof 常用来判断一个变量是否为空,或者是什么类型的.但它们之间还是有区别的: typeof typeof 是一个一元运算,放在一个运算数之前 ...
- twisted(2)--聊天系统
我们今天要做一个聊天系统,这样可以和我们之前flask api那系列文章结合起来:其次,聊天系统最能代表tcpserver,以后可以套用各种模型,比如我们公司做的物联网,其实就是把聊天系统简化一下. ...
- 如何给网页标题栏上添加图标(favicon.ico)
favicon.ico详解: favicon是Favorites Icon的缩写,favicon.ico是指显示在浏览器收藏夹.地址栏和标签标题前面的个性化图标. 设置步骤: 1. 把做好的f ...
- d3可视化实战03:神奇的superformula
需求驱动实现 前文讲过了D3的数据驱动机制,中间所举的例子都很简单.例如那个demo里面,绑定的数据是一个简单的数组,实现的图元也仅仅是一堆用SVG画的circle.但是现实世界中我们往往会遇到复杂的 ...
- 我只能说,CDH5真的屌爆了!!!
参考URL http://blog.csdn.net/yangzhaohui168/article/details/34185579 http://blog.csdn.net/yangzhaohui1 ...