anon_dcs3spp
anon_dcs3spp

Reputation: 3022

Is there a Jest hook that can be used to exit testing if some pre-conditions are not met?

I am developing a NodeJS server app and have the following query.

Is there a Jest hook that exists that can check for a condition(s) and will only starts testing if true? If the condition is not true then the test process does not start and a message is displayed on console.

If not, then guess I could use package.json pre-script that will trigger a shell script that performs conditional check(s).

Upvotes: 4

Views: 868

Answers (1)

Estus Flask
Estus Flask

Reputation: 222503

Places that are common to a group of tests can be used.

For a specific test group it's beforeAll:

beforeAll(async () => {
  ...
  if !(condition)
    throw new Error('Condition not met');
});

For all test suites it's setup file:

module.exports = async () => {
  ...
  if !(condition)
    throw new Error('Condition not met');
};

Upvotes: 3

Related Questions