reactjs - Inconsistent Unexpected Token: < -
i have unit test in mocha react component works:
var should = require('should'); require('./testdom')('<html><body></body></html>'); describe('update-button', function () { var querya = {some object}; var queryb = {some different object}; var reporta = {currentquery: json.stringify(querya)}; var reportb = {currentquery: json.stringify(queryb)}; var react = require('react/addons'); var testutils = react.addons.testutils; var updatebuttons = require('../client/src/js/components/updatebuttons'); it('returns apply button', function() { var updatebutton = testutils.renderintodocument( <updatebuttons query={querya} defaultquery={json.stringify(queryb)} report={reportb} /> ); var update = testutils.findrendereddomcomponentwithclass(updatebutton, 'update'); should.exist(update.getdomnode().children); update.props.children.should.equal('apply'); }); it('returns default button', function() { var updatebutton = testutils.renderintodocument( <updatebuttons query={queryb} defaultquery={json.stringify(querya)} report={reportb} /> ); var update = testutils.findrendereddomcomponentwithclass(updatebutton, 'setdefault'); should.exist(update.getdomnode().children); update.props.children.should.equal('make default'); }); }); mocha deals fine , 2 tests pass.
and have test, change name of the component , add different functionality:
var should = require('should'); require('./testdom')('<html><body></body></html>'); var react = require('react/addons'); var testutils = react.addons.testutils; var allocationchart = require('../client/src/js/components/allocationchart'); function emptyfunction() { return "fired"; } describe('allocation-chart', function () { var values = [{"x":0,"y":0.0007445807134429661,"pvalue":0.23962495642627535},{"x":1,"y":0.0017470479717729415,"pvalue":0.06222155778588356},{"x":2,"y":0.001213604360619125,"pvalue":0.3751442982987042},{"x":3,"y":-0.0007938410728732803,"pvalue":0.6306601384568038},{"x":4,"y":-0.0013313112686847983,"pvalue":0.4930399112767866},{"x":5,"y":-0.0002447714978416893,"pvalue":0.906972528582401},{"x":6,"y":0.0008058818608920326,"pvalue":0.6581667787665311}]; var valueextent = [-0.5, 0.5]; it('is created', function() { var sparkline = testutils.renderintodocument( <allocationchart key={1} highlightbar={emptyfunction} newhighlightbar={emptyfunction} values={values} valueextent={valueextent} highlightrow={emptyfunction} dehighlightrow={emptyfunction} /> ); var chart = testutils.scryrendereddomcomponentswithclass(sparkline, 'allocationchart'); chart.length.should.equal(1); should.exist(chart.getdomnode()); var sparklinebins = testutils.scryrendereddomcomponentswithclass(sparkline, 'sparklinebin'); sparklinebins.length.should.equal(7); }); it('fires hover event', function() { var sparkline = testutils.renderintodocument( <allocationchart key={1} highlightbar={emptyfunction} newhighlightbar={emptyfunction} values={values} valueextent={valueextent} highlightrow={emptyfunction} dehighlightrow={emptyfunction} /> ); var sparklinebins = testutils.scryrendereddomcomponentswithclass(sparkline, 'sparklinebin'); var responsea = testutils.simulate.mouseover(sparklinebins[0]); var responseb = testutils.simulate.mouseout(sparklinebins[0]); responsea.should.equal("fired"); responseb.should.equal("fired"); }); but instead of working, returns following error:
<allocationchart ^ warning: unexpected token < use --force continue. aborted due warnings. and have no idea how or why or how happen.
elijah identified problem. here's solution:
move
compiler.jsout of test directory mocha won't load test file.create
mocha.optsfile inside test directory. should contain:--compilers .:compiler.jsthe module path passed
--compilersrelative directory mocha runs. way hammerlab.org clear compiler loaded using--compilers. use ofmocha.optsavoids having pass parameter requirejs every single time.
Comments
Post a Comment