Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 1.76 KB

5. writing-unit-tests.md

File metadata and controls

59 lines (40 loc) · 1.76 KB

Contribution Guide

  1. Getting Set up
  2. Building Samples and Packages
  3. Running a Sample or Storybook
  4. Testing your changes
  5. Writing unit tests
  6. Submitting a PR
  7. Having your changes published

5. Writing unit tests

Our unit tests are written using Jest.

Tips for writing unit tests

  • All unit tests must be in a .test.ts or .test.tsx file - jest will automatically pick up these files and run them.

  • Unit tests must be well named and test only one thing per test.

  • Unit tests must follow the Arrange, Act, Assert pattern, e.g.

    test("addOne function should add one to a given number", () => {
        // Arrange
        const givenNumber = 5;
    
        // Act
        const result = addOne(givenNumber);
    
        // Assert
        expect(result).toEqual(6);
    });
    • This ensures good structure to unit tests making them easily understandable for the developer who needs to take a look at them when they do not pass.
  • UI components must have snapshot tests (see Generating new snapshots)

Running unit tests

To run unit tests for the package or sample you are in:

rushx test # run this from the package directory

To run all unit tests for the whole repo

rush test # this can be run from anywhere

Debugging unit tests

Documentation to follow.