A development test workflow with the F key

When we hit w, we get a new list of commands that we can run to continue with our test suite and do more for it. We've already explored these options a little bit, but it's worth reiterating the work that we can (and should) do during development and talk a little bit about when to use these tests as well!

The first major one is the following:

Press f to run only failed tests

We'll use this one a lot. Often when you're developing complex applications you might introduce changes that break your test suite, or you might be going with more of a test-driven development approach, in which case you'll be working with broken tests and then fixing things in your application or in your tests until the tests pass again! If that's the case, you'll be using this command a lot, so get comfortable with it early! If we try to run this now without any failed tests, we'll get the following output:

No failed test found.
Press `f` to quit "only failed tests" mode.

Watch Usage: Press w to show more.

This makes sense. We had no failed tests, so of course it wouldn't find any and thus wouldn't run any tests. We can make this work for us, though, by introducing a failing test intentionally and then running our full test suite, followed by just the failed tests! We can simulate this very quickly by returning back to src/App.js and commenting out the export statement at the bottom of the code:

// export default App;

Now if you restart your tests, you will get one failing test! We should be able to hit F and it will rerun the single failing test (and we can repeat this process over and over, as well). Now if we uncomment that line and save the file, if we rerun our test suite (either automatically or manually using F), we should be back to a fully-working test suite!

There's another reason to get comfortable with rerunning failed tests: you should get comfortable with the idea of writing tests that intentionally fail until you make the test pass, or passes unless you comment or intentionally break the code! If you make code changes that should break your tests but the test still passes, that means your tests aren't actually testing the behavior of your application correctly!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.143.239