Testing

Why do we need testing?

  • Create more resilient code
  • It's an in-demand skill
  • Test-Driven Development

Test-Driven Development

  1. Write a test
  2. Run test (it should fail)
  3. Write just enough code for the test to pass
  4. Run test (it now passes)
  5. Refactor code, make improvements
  6. Repeat process

Unit Testing

  • Write code to test code
  • isolate specific units of your code.
  • Following a recipe
  • Jest

End-to-End

  • Test whether the app is functioning from start to finish.
  • Cypress

We're going to focus on Unit Testing, using Jest

Jest helps us test:

  • Vanilla JS
  • React apps
  • React Native apps
  • Many other JS frameworks

Best Practices

  • Have only one assert per test method
  • Avoid test interdependence
    • Each test takes care of its own setup and teardown
    • Don't let tests rely on other tests
  • Keep tests simple and easy to read

Sling
Some
Code

Testing

By jonmcd

Testing

  • 155