After reading this article you should checkout other common mistakes using RTL here: https://kentcdodds.com/blog/common-mistakes-with-react-testing-library Ever noticed this warning in your tests? Noise like this in test runs can be really annoying, and if we read the error in a bid to find out how we might get rid of it, we might think – well… Continue reading React Testing Lib – don’t misuse act
Category: Jest
Jest – think integration
I want to use an example form component that uses react-hook-form, you can see it featured in my recommended packages post here. Let’s start by creating our form component. And now FirstField.tsx Let’s just assume that the implementation of SecondField is much the same as FirstField, but without the useEffect, and for the purpose of… Continue reading Jest – think integration
Jest/TypeScript – partial type mock
Consider these types: Let’s say you are testing a component that fires off an API call to retrieve on object that should match IHuman. In your test you will want to create a mock version of this, – usually referred to as stub or a fixture. Let’s look at an example of how that might… Continue reading Jest/TypeScript – partial type mock
Jest/React – mocking async functions
Let’s say you have a component that calls to an API in a useEffect. This API data will be used to update some component state. When writing a component test you will want to mock this API call and provide a stub for it. Many times I have seen code that looks like this: What… Continue reading Jest/React – mocking async functions
Jest – function call assertions
When writing tests with Jest you might want to write assertions that check expected function calls, your code might look a bit like this: This certainly gets us part of the way, but by itself, this assertion is weak. Why is this? Firstly we are not checking how many times our logic is calling the… Continue reading Jest – function call assertions