Jest: Ignore "Your test suite must contain at least one test."

Created on 26 Oct 2018  ·  4Comments  ·  Source: facebook/jest

💬 Questions and Help

Hello.

I want to write tests in normal file itself as described below:

src/add.js

//private
function sum(a, b) {
  return a + b;
}

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

src/subtract.js

//private
function subtract(a, b) {
  return a - b;
}

//no test

After running `jest src/*output is as follows:

 FAIL  src/subtract.js
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at ../node_modules/jest/node_modules/jest-cli/build/TestScheduler.js:256:22

But, I want to ignore files don't have any tests.
How can I do it?

Thanks.

Most helpful comment

You can add an empty test.skip('skip', () => {}) to the subtract.js file. We won't remove this message nor make it configurable, as we optimize for common use case – this is clearly not one of them.

All 4 comments

Hey @hattys2
Could you share your use case for putting your test within the src file itself? I've yet to see someone have the setup you have.

@natealcedo
Just like src/add.js
I found similar case: https://github.com/facebook/jest/issues/4316

You can add an empty test.skip('skip', () => {}) to the subtract.js file. We won't remove this message nor make it configurable, as we optimize for common use case – this is clearly not one of them.

Thanks. I'll try it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hramos picture hramos  ·  3Comments

paularmstrong picture paularmstrong  ·  3Comments

withinboredom picture withinboredom  ·  3Comments

StephanBijzitter picture StephanBijzitter  ·  3Comments

mmcgahan picture mmcgahan  ·  3Comments