Search code examples
unit-testingtestingjestjs

How to ignore empty test files in Jest from throwing error


I am working on a project and I want to maintain its folder structure, so for each controller file, I have a controller.test file, but sometimes, I might have empty test files, because of some reasons, when I have such situations, Jest throws errors, since the number of files is huge it's making really hard to find test fails from lots empty test file messages.

Does Jest have any configuration to prevent throwing error messages on empty test files?


Solution

  • Your best bet is to set those test to be skipped as todos.

    An example of an empty test that passes without problem with a nice todo annotation would look something like this:

    (logger.spec.ts)
    
    
    describe('Logger', () => {
        test.todo('please pass');
    });
    

    The result is:

     PASS  e2e/logger.spec.ts
      Logger
        ✎ todo please pass