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.
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?
Top comments (5)
Awesome Feature!!
I used to put comments on the component itself until a friend recommended this article to me in a code review.
Nice job, Thank you! 🧡
This feature is nuts!
However, I am wondering if there is a built-in way to make
test.todo
jest failing for CI purposes.Thank you for this helpful article, this helped me out in a long search of how to do this. Much thanks, Duncan Haywood.
Is there a way of listing all the 'todo' tests quickly, rather than having to go through every test?
Awesome feature! thank you!