1

I was trying to do unit testing for a react component. But when I tried to render it using TestUtils.renderIntoDocument() method jest throws an error

Error: Line 1: Unexpected token ILLEGAL
    at constructError (node_modules/esprima/esprima.js:2406:21)
    at createError (node_modules/esprima/esprima.js:2425:17)
    at unexpectedTokenError (node_modules/esprima/esprima.js:2500:13)
    at throwUnexpectedToken (node_modules/esprima/esprima.js:2504:15)
    at scanPunctuator (node_modules/esprima/esprima.js:842:13)
    at advance (node_modules/esprima/esprima.js:1621:16)
    at lex (node_modules/esprima/esprima.js:1690:78)
    at expect (node_modules/esprima/esprima.js:2520:21)
    at parseFunctionSourceElements (node_modules/esprima/esprima.js:4827:9)
    at parseFunctionExpression (node_modules/esprima/esprima.js:5073:16)

Poiting to nowhere inmy code. So I tried removing elements one by one and figured that the image component might be causing the probelm.

 <span><input type="image" title="cc" src={require('../../assets/images/cc.png') }></input></span>

saw an almost similer issue happened in react-native in this post. If anybody can show some light on it. It will be great.!

Thanks

Rick Hanlon II
  • 20,549
  • 7
  • 47
  • 53
P-RAD
  • 1,293
  • 2
  • 15
  • 36
  • Do you use something like wepback? If no, seems like src expects string, but require returns file content, and you get this ILLEGAL stuff. – Sergii Shvager Aug 23 '16 at 08:14
  • @SergeyShvager got it working apologies for late update.. it was require I just removed the require around the image path . and it works now .. thanks for your time – P-RAD Aug 23 '16 at 16:13

0 Answers0