This video is available to students only

Testing a component library is similar to application testing. Our tests should resemble how consumers will actually use our library. Testing is a complex topic that deserves its own course and we will just be scratching the surface. In this module we will be setting up a basic testing environment using React Testing Library and ts-jest.

React Testing Library has several guiding principles that help ensure that your tests are as flexible and accurate as possible. ts-jest is a TypeScript pre-processor that ensures Jest is able to consume and type-check our tests.

ts-jest configuration#

Since ts-jest is a pre-processor for Jest, the setup is similar to a non-TypeScript codebase. To start, we will add jest and ts-jest.

Next we add a Jest configuration that uses ts-jest as a preset. Create a new jest.config.js file.

Jest is now configured to consume any TypeScript tests we write. We can update our test script in the package.json file to use Jest.

No discussions yet. Be the first. All notification go to the author.