Jest has a 'Your test suite must contain at least one test.' rule. It complains that if I have a file that isn't a test suite it cannot exist in the __test__/
directory that I have created (see below). This basically means everything in that folder (including the subfolders) must be a test suite.
How do I get around this? I really want to store my mock data objects with my test suites.
Next we call a global Jest function describe(). In our TweetUtils-test. js file we're not just creating a single test, instead we're creating a suite of tests. A suite is a collection of tests that collectively test a bigger unit of functionality.
Calling skip in your test utility file will suppress that rule violation:
test.skip('Workaround', () => 1)
Adding this for completeness. Brian's testMatch
/testRegex
solution seems more clean to me.
The default glob patterns that Jest
uses to find test files are
[ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]
In other words...
By default it looks for
.js
,.jsx
,.ts
and.tsx
files inside of__tests__
folders, as well as any files with a suffix of.test
or.spec
(e.g.Component.test.js
orComponent.spec.js
). It will also find files calledtest.js
orspec.js
.
Because mockData.js
is in a subdirectory of __tests__
it is being found by the default glob patterns and assumed to be a test.
To keep Jest
from treating mockData.js
as a test you can change the glob patterns Jest
uses to find tests with the testMatch
configuration option, or to use regular expressions instead of glob patterns use testRegex
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With