Name front-end test cases from user perspective

Published on in JavaScript, React and Testing

Such naming helps you create tests that resemble the way your users use your app.

I noticed that a colleague from another team had named their test cases from user perspective, like this:

describe('<FooComponent>', () => {
  test('user can see all options', () => {
    // ...
  })

  test('user can toggle between options', () => {
    // ...
  })

  // etc.
})

I was already familiar with the primary guiding principle of React Testing Library:

The more your tests resemble the way your software is used, the more confidence they can give you.

But I hadn't thought of naming test cases from this perspective. Makes sense, though! Naming test cases from user perspective helps you create good tests – tests that resemble the way your users use your app.