Javascript mocha未重新加载源React组件.jsx文件
我正在用摩卡来测试我的反应成分。我像这样设置package.jsonJavascript mocha未重新加载源React组件.jsx文件,javascript,reactjs,mocha.js,babeljs,Javascript,Reactjs,Mocha.js,Babeljs,我正在用摩卡来测试我的反应成分。我像这样设置package.json { "name": "client", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "NODE_ENV=test mocha './app/**/*.spec.js' --compilers js:babel-core/register --require testSetup.js",
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test mocha './app/**/*.spec.js' --compilers js:babel-core/register --require testSetup.js",
"test:watch": "npm test -- --watch",
"start": "NODE_ENV=dev node server.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"aphrodite": "^0.2.0",
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.7.2",
"css-loader": "^0.23.1",
"enzyme": "^2.2.0",
"eslint": "^2.6.0",
"eslint-plugin-react": "^4.2.3",
"expect": "^1.16.0",
"jsdom": "^8.2.0",
"mocha": "^2.4.5",
"mocha-jsdom": "^1.1.0",
"node-sass": "^3.4.2",
"npm-install-webpack-plugin": "^3.0.0",
"react-addons-test-utils": "^0.14.8",
"react-dom": "^0.14.8",
"react-hot-loader": "^1.3.0",
"sinon": "^1.17.3",
"style-loader": "^0.13.1",
"webpack": "^1.12.14",
"webpack-dev-server": "^1.14.1",
"webpack-notifier": "^1.3.0"
},
"dependencies": {
"axios": "^0.9.1",
"cuid": "^1.3.8",
"delay": "^1.3.1",
"fecha": "^2.1.0",
"file-loader": "^0.8.5",
"history": "^2.0.1",
"intl": "^1.1.0",
"lodash": "^4.6.1",
"react": "^0.14.8",
"react-addons-shallow-compare": "^0.14.8",
"react-dom": "^0.14.8",
"react-redux": "^4.4.1",
"react-router": "^2.0.1",
"react-router-redux": "^4.0.0",
"redux": "^3.3.1",
"redux-crud": "^1.0.0",
"redux-saga": "^0.9.5",
"reselect": "^2.2.1",
"seamless-immutable": "^5.1.1",
"url-loader": "^0.5.7"
}
}
下面是用于测试Selector.jsx组件的测试文件Selector.spec.js:
import React from 'react';
import { shallow, mount } from 'enzyme';
import sinon from 'sinon';
import expect from 'expect';
import Selector from './Selector.jsx';
describe('Selector Component', function () {
const setup = (optionalProps={}) => {
const props = {
onChange: sinon.spy(),
value: '3',
values: ['1','2','3','4'],
...optionalProps
}
const output = mount(<Selector {...props} />)
return {
output,
props,
}
}
describe('when using scalar values', function () {
it('should allow all props to be passed down', () => {
const { output, props } = setup()
const actual = output.props()
const expected= props
expect(actual).toEqual(expected)
});
});
});
从“React”导入React;
从“酶”导入{shall,mount};
从“sinon”进口sinon;
从“expect”导入expect;
从“/Selector.jsx”导入选择器;
描述('Selector Component',function(){
const setup=(optionalProps={})=>{
常量道具={
onChange:sinon.spy(),
值:“3”,
值:['1','2','3','4'],
…可选道具
}
常量输出=装入()
返回{
产出,
道具,
}
}
描述('使用标量值时',函数(){
它('应该允许所有道具被传递',()=>{
const{output,props}=setup()
const actual=output.props()
预期常数=道具
预期(实际)。toEqual(预期)
});
});
});
最后,Selector.jsx本身:
import React, { PropTypes } from 'react';
import map from 'lodash/map';
const Selector = ({
onChange,
value,
values, // [{value, name}]
}) => (
<select onChange={e=>onChange(e.target.value)}
value={value}
>
{values[0].value
? map(values, (val,i) =>
<option
key={i}
value={val.value}
>
{val.name} boo!
</option>
)
: map(values, val =>
<option
key={val}
value={val}
>
{val}
</option>
)
}
</select>
)
Selector.propTypes = {
onChange: PropTypes.func.isRequired,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
values: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.shape({
value: PropTypes.any.isRequired,
name: PropTypes.string,
})),
PropTypes.array
]).isRequired,
};
export default Selector;
import React,{PropTypes}来自'React';
从“lodash/map”导入地图;
常量选择器=({
一旦改变,
价值
值,//[{value,name}]
}) => (
onChange(e.target.value)}
value={value}
>
{值[0]。值
?映射(值,(val,i)=>
{val.name}boo!
)
:映射(值,val=>
{val}
)
}
)
Selector.propTypes={
onChange:PropTypes.func.isRequired,
值:PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
值:PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.shape({
值:PropTypes.any.isRequired,
名称:PropTypes.string,
})),
PropTypes.array
]).要求,
};
导出默认选择器;
所以现在发生的事情是,每当我保存测试文件Selector.spec.js时,它都会重新运行测试,但是我对源文件所做的任何更改都不会被测试拾取,我必须按住ctrl+c组合键终止测试并重新启动它。发生这种情况有什么原因吗
谢谢大家! 我也面临同样的问题,你找到解决办法了吗?