jasmine - SyntaxError: Unexpected token static -
i'm trying evaluate different testing frameworks work react, , turns out jest on list. however, i'm trying use static properties outlined here: https://github.com/jeffmo/es-class-fields-and-static-properties.
so, took tutorial given on jest homepage, , added static proptypes property, code looks this:
import react 'react'; class checkboxwithlabel extends react.component { static defaultprops = {} constructor(props) { super(props); this.state = {ischecked: false}; // since auto-binding disabled react's class model // can prebind methods here // http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding this.onchange = this.onchange.bind(this); } onchange() { this.setstate({ischecked: !this.state.ischecked}); } render() { return ( <label> <input type="checkbox" checked={this.state.ischecked} onchange={this.onchange} /> {this.state.ischecked ? this.props.labelon : this.props.labeloff} </label> ); } } module.exports = checkboxwithlabel;
when run tests (npm test or jest), throws following error:
➜ jest using jest cli v0.8.2, jasmine1 fail __tests__/checkboxwithlabel-test.js ● runtime error syntaxerror: desktop/jest/examples/react/checkboxwithlabel.js: unexpected token (5:22)
my package.json file looks this:
{ "dependencies": { "react": "~0.14.0", "react-dom": "~0.14.0" }, "devdependencies": { "babel-jest": "*", "babel-preset-es2015": "*", "babel-preset-react": "*", "jest-cli": "*", "react-addons-test-utils": "~0.14.0" }, "scripts": { "test": "jest" }, "jest": { "scriptpreprocessor": "<rootdir>/node_modules/babel-jest", "unmockedmodulepathpatterns": [ "<rootdir>/node_modules/react", "<rootdir>/node_modules/react-dom", "<rootdir>/node_modules/react-addons-test-utils", "<rootdir>/node_modules/fbjs" ], "modulepathignorepatterns": [ "<rootdir>/node_modules/" ] } }
any ideas on i'm missing here?
thanks.
any ideas on i'm missing here?
class properties neither part of es2015
nor react
preset.
you have load plugins handles class properties:
npm install babel-plugin-transform-class-properties babel-plugin-syntax-class-properties
and in .babelrc
file (next existing plugins or presets):
"plugins": [ "syntax-class-properties", "transform-class-properties" ]
Comments
Post a Comment