Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Better error messaging for acorn parsing errors when testing React #693

Closed
dcousineau opened this issue Mar 30, 2016 · 3 comments · Fixed by #903
Closed
Labels

Comments

@dcousineau
Copy link
Contributor

If JSX code is inlined into a test assertion (e.g. using enzyme's .contains, etc) acorn from the power-assert library fails hard (fails hard enough to kill the --watch watcher):

test("some test", t => {
    //...
    const wrapper = shallow(<Lesson {...props} />);
    t.true(wrapper.contains(<div className="page-container is-kiosk-mode" />));
});
/Users/dcousineau/Projects/frontend/node_modules/acorn/dist/acorn.js:945
  throw err;
  ^

SyntaxError: Unexpected token (1:24)
    at Parser.pp.raise (/Users/dcousineau/Projects/frontend/node_modules/acorn/dist/acorn.js:943:13)
    at Parser.pp.unexpected (/Users/dcousineau/Projects/frontend/node_modules/acorn/dist/acorn.js:1503:8)
...

The solution to fix this error is a very simple:

test("some test", t => {
    //...
    const wrapper = shallow(<Lesson {...props} />);
    const actual = wrapper.contains(<div className="page-container is-kiosk-mode" />);
    t.true(actual);
});

It would be nice if AVA could expect and catch this error, prevent it from hard exiting the process, and possibly display messaging like "Unparseable (possibly JSX) code found in your test assertion. Try assigning the code to a variable first then running the assert against the variable".

@twada
Copy link
Contributor

twada commented Mar 30, 2016

@dcousineau Thank you for reporting. That's a power-assert's problem and I'm trying to solve it. Sorry for inconvenience... I'll integrate it to AVA as soon as possible when the PR lands. So please stay tuned.

@novemberborn
Copy link
Member

@dcousineau which version are you using? Could you try with master? If it still crashes perhaps you could share an example repo so I can fix the watcher crash? Thanks!

@babsonmatt
Copy link

Same issue here. Using ava 0.14.0 and enzyme 2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants