Skip to content

12_Unit Testing

David Wyss edited this page Sep 1, 2022 · 5 revisions

We use Jest for unit testing in both frontend and backend.

The nomenclature for test files is as follows: <filename>.spec.ts. Thus, the test file for user.resolver.ts would be named user.resolver.spec.ts, and would be located in the same folder.

In testing, we generally follow Jest's suggested approach. Tests are grouped in describe blocks that should have a descriptive name.

describe('UserResolver', () => {
  
  beforeEach(async () => {
    <things to execute before every test>
  });

  <tests go here>
}

Each test is then structured as follows:

it('should do something'), async () => {
  <test contents go here>
}

Tests and test groups should have descriptive names, so in case of test failure in e.g. an automated GitHub action, it's easy to determine what went wrong.