Introduction to Testing
Let's run the test suite to make sure everything is working as expected (you can keep the dev server running and start this in a second terminal window):
yarn rw test
The test
command starts a persistent process which watches for file changes and automatically runs any tests associated with the changed file(s) (changing a component or its tests will trigger a test run).
Since we just started the suite, and we haven't changed any files yet, it may not actually run any tests at all. Hit a
to tell it run all tests and we should get something like this:
If you cloned the example repo during the intermission and followed along with the Storybook tutorial in this chapter, the test run should finish and you will see something like this:
Note that the summary on the bottom indicates that there was 1 test that failed. If you feel curious, you can scroll up in your terminal and see more details on the test that failed. We'll also take a look at that failed test shortly.
If you continued with your own repo from chapters 1-4, you may see some other failures here or none at all: we made a lot of changes to the pages, components and cells we generated, but didn't update the tests to reflect the changes we made. (Another reason to start with the example repo!)
To switch back to the default mode where test are only run for changed files, press o
now (or quit and restart yarn rw test
).
What we want to aim for is all green in that left column and no failed tests. In fact best practices tell us you should not even commit any code to your repo unless the test suite passes locally. Not everyone adheres to this policy quite as strictly as others...<cough, cough>
We've got an excellent document on Testing which you should definitely read if you're brand new to testing, especially the Terminology and Redwood and Testing sections. For now though, proceed to the next section and we'll go over our approach to getting that last failed test passing.