-
Notifications
You must be signed in to change notification settings - Fork 973
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
Proposal: Update cell tests to just test that nothing is thrown #1397
Conversation
100% agree. Only detail I'd change is render the Cell itself |
What does an |
Sorry, I think I'm mixing up some stuff at the moment. What I suggested would indeed require mock setup, and changing the output (i.e. running through the tutorial) would make it fail. Disregard my comment! Let me try again: I 100% agree. |
For reference, here's the current suggested Cell Test template that's queued up in the Testing Project Board to be implemented:
^^ I would also love to see this happen. The journey with tests so far seems to be an attempt to balance:
I think Robert's proposed solution in #629 is an attempt to avoid being narrow, e.g. test the Cell and not the specific Failure, Succes, e.g. components. But that might be too broad (doesn't check for Null or Loading, although it could). I think Rob's proposal to check for "not throwing" hits the right expectation for being meaningful. Maybe, via comments, there could be a quick example or two about how to test for specific content if the user wants to do so? My suggestion at this point:
|
That Issue was opened long before @peterp came up with the |
It does as there's been an ongoing conversation (and PRs) that keep looping back to the Issue. E.g Robert's comment with the template I referenced above came after I updated the current Cell test template to use the mock file. Robert's intent was to focus the testing on the Cell component instead of each specific "state" component within the cell, which seemed like a good evolution. But I'd agree it seems out of sync that he did not include the use of the Cell.mock.js file for the data. I understand that using the Mock file for the data structure is how Peter intended this to work together. But I missed a point on my bulleted list to be explicit about using the Cell.mock.js for data, which would be a change to Robert's template. Now edited and added it to the list (sorry I missed it the first time). More clear? (or just more muddy?) |
After discussing with @thedavidprice I'm going to add a comment in here along the lines of "when you're ready to test the actual output of your component..." and then, when ready, also add a link to our testing docs. |
Closes #629 |
I think my template was after the update, and briefly before we discussed not writing tests at all. I think having templates that check for throwing is a good middle ground |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
I like it, @cannikin! Moving this forward adds great motivation on my end to wrap up the remaining Testing Project Board items this week. |
Now just gotta get the checks to pass 😬 |
Right now the cell tests are testing very specific (sometimes the exact) text output from each state (Loading, Empty, Failure, Success). As soon as you change anything in any of these functions, the test fails. I feel like this is not ideal for new developers, or new-to-Redwood developers—a failing test inherently signals to you that you did something "bad" but in this case you just started building out your real functionality. Why should they be "punished" for that?
I propose that the default Cell tests follow the lead of the default Component, Page and Layout tests: just check that no errors are raised. Once you get your component/cell dialed in you can update your test to target specific output, but when you're just building them out the safest thing to check is that no errors are raised:
It still uses the mocks, and passes them to the components for rendering, but the expectation is just that you didn't horrifically break anything.
I think we can agree that having a Page test that tested for the presence of the default "Find me in web/src/pages/HomePage/HomePage.js" since will pass once or, if they don't bother running the suite, never! Users are guaranteed to change it, and break the test, and have to change that as well. So let's not force them to do extra work just to get started in a Cell either.
We're seeing this cause issues specifically during the tutorial—by the time you finish, if you were to run the test suite, you'd get failures in all of your cells. I don't think this is a good first experience for users. I would love, at the end of part 1 of the tutorial, to tell the reader:
Before I could start on part 2 of the tutorial I had to update the test suite so that I could start out new users with everything being green. Let's default them to the happy path and then explain to them the virtues of adding tests and keeping them up-to-date with their component code.
/cc @mojombo @RobertBroersma