Use test.todo() when writing Jest tests.

karltaylor profile image Karl Taylor ・1 min read

When I start building a new component, I can sometimes completely forget to write tests as I am going, or perhaps I've finished writing my component, and I don't fully remember what I should be writing in my test suite.

A quick solution to this if you are using Jest is to build your test suite, and replace your tests with test TODOS!

describe('NewsContent', () => {
  it('Should render a normal string', () => {}) // Passes, but it's not complete! ☹️
  it('Should render a very long string') // This will fail ☹️

Instead, we can do it.todo('My todo test description').

describe('NewsContent', () => {
  it.todo('Should render a normal string') // This will show up as a todo in our test suite! Woohoo! 

The beauty of this is that we get visual feedback in our test suite in the terminal that we have outstanding tests to finish.

Alt Text

Now you never have a reason to not hit that diff-coverage threshold 🤓

What is your go-to process when building new components and adding tests?

Posted on by:

karltaylor profile

Karl Taylor


Software Developer / Indie Hacker


markdown guide

Is there a way of listing all the 'todo' tests quickly, rather than having to go through every test?