我已經將我的React組件全部充實,並且我想了解如何使用Mocha + chai正確地測試這些組件。我有這些配置對於我package.json
(相關的):用摩卡測試React組件:意想不到的標記
"scripts": {
"start": "http-server",
"build": "watchify main.js -t babelify -o bundle.js",
"test": "./node_modules/mocha/bin/mocha --compilers js:babel-core/register test/test*.js"
},
"devDependencies": {
"babel": "^5.6.23",
"babelify": "^6.1.3",
"browserify": "^11.0.0",
"chai": "^3.5.0",
"jsdom": "^9.8.3",
"mocha": "^3.2.0",
"react-addons-test-utils": "^15.4.1"
},
"babel": {
"presets": [
"es2015"
]
}
我有Skill.js
:
import React from 'react';
import _ from 'underscore';
export default class Skills extends React.Component {
render() {
return (
<div>
<h1>T E S T</h1>
</div>
)
}
}
一個文件夾中test.js
稱爲test
沿:
import React from 'react';
import { expect, assert } from 'chai';
import Skills from '../src/components/Skills.js';
我當我運行npm test
時收到意外的令牌錯誤。
什麼是控制檯抱怨?爲什麼<div>
標籤無效?
可能你需要''預設值':[「react」,「es2015」]' –