i using mocha test react components. set 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", "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" } }
and here test file selector.spec.js used test selector.jsx component:
import react 'react'; import { shallow, mount } 'enzyme'; import sinon 'sinon'; import expect 'expect'; import selector './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 props passed down', () => { const { output, props } = setup() const actual = output.props() const expected= props expect(actual).toequal(expected) }); }); });
and finally, selector.jsx itself:
import react, { proptypes } 'react'; import map '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;
so happens whenever save test file, selector.spec.js, reruns test, none of changes have made source file picked test, have ctrl+c kill test , restart it. there reason why happening?
thank you!
Comments
Post a Comment