Knowing what to test

23 July 2021, Thai Vu.

A simple and opinionated guide.

What the tests are for

We write tests to make sure our application/modules work as intended for the users. To achieve that, we should be able to cover most real-life use cases from our users’ perspectives. Identifying those use cases is a crucial step for realising them into our tests later.

We write both unit and integration tests, but we should put much more emphasis on the latter. Write unit tests for utility functions, and integration tests for parent components at page- or module-level. Unit tests are always nice to have but as the size and complexity of the project grow larger, they can and will become a nuisance to write and maintain, not to mention the blazing CI running costs.

What to include in the tests

We should strive to be as user-centric as we possibly can.


Let’s say we implement a simple popup modal for confirmation on deleting an item, we should aim to test what happens when:

  1. the user clicks the button that trigger the modal’s opening
  2. check if the texts and the buttons are visible on the modal
  3. what should happen when the user clicks either buttons:
    • user clicks OK → the (mocked or not) DELETE API endpoint is called once or the delete action gets dispatched to the store → the modal is closed.
    • user clicks Cancel → the modal is closed.

Hope this helped, and have fun writing tests!