-
-
Notifications
You must be signed in to change notification settings - Fork 445
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
Some part of the tutorial breaks the tests included in create-react-app #219
Comments
@iggirex Here is the error I see when I run
But this is normal because you'd need to configure your tests to run with React Router. I'm not sure what the error is that you are seeing. Can I see your |
Sure @jayair, I don't think I've added anything outside of what the tutorial said to do. I did change the "test" script to "jest", as I described in the OP.
|
@iggirex Yeah the only thing that is different for me is the |
@jayair there were several places that suggested to change that script, here is one of them on the facebook/jest GH: jestjs/jest#3436 It's a little ways down, I haven't tried installing "watchman" since 1) it's deprecated and 2)I don't know what it does or why add it to create-react-app, but I'm running out of other solutions so i might try that soon here. |
I went back through my commit history and found the place where the tests start to break. I should mention though, that the error messages when trying to run tests are very different in these earlier commits than when the project is finished (notice the newer errors up in the OP, and these diff error messages back in the commit history)
This is what the file looks like when it's breaking:
And this is the error I get when these lines are added to the project:
When I comment out both lines, the tests work. |
Started the tutorial from scratch, I can confirm this is the step where the tests stop working (the errors are identical to the the ones in the post directly above this one): https://serverless-stack.com/chapters/create-containers.html "And go ahead and remove the code inside src/App.js and replace it with the following."
I realize there is some bad things that happen to React tests when you start using React Router, I'm still pretty new to it and don't know much about this or how to fix it. I'll make another post once I find a fix. I think it would be good to at least have a warning, if not a workaround, to inform people doing the tutorial. |
@iggirex Yeah this is the error you will probably see. This is because if you are tests components that rely on the Router, you'll need to provide them with a context - https://stackoverflow.com/a/43775325 |
@jayair you were right about having to add context. I was having some different issues as well trying to figure out what my test script should be (in package.json) and getting a CRA dependency called watchman to work. I've detailed my solution in this SO post: |
@iggirex Thanks for following up. I'll direct people to this issue in case people run in to something similar. |
The tests included in create-react-app do not work if you follow this tutorial to the end.
create-react-app tests work fine for me when I first generate a project, but for the code I built using this tutorial the very basic tests (just test to see if a component loaded up on a page) break.
I mentioned this in the comment section of "Wrapping Up" and got confirmation from @jayair that his tests were broken as well. (though he had a different error message).
My original post explaining the problem:
I didn't run any tests during this tutorial, and by the end of it, the standard create-react-app tests are broken for me. Running "npm test" yields:
On the Jest and Facebook GH issues they suggest changing the npm command from
"test": "react-scripts test --env=jsdom",
to
"test": "jest",
which then yields a different error:
It seems to be a problem with babel maybe? It has a problem with the JSX caret symbol. When I run a brand new create-react-app and run 'npm test', tests work fine. I'm using latest npm. I've tried deleting node_modules, package.json.lock and reinstalling them, but the problem is still there. Anyone else having this issue? (Great tutorial by the way, I think adding one test at the end to show that tests work would make it stronger).
The text was updated successfully, but these errors were encountered: