Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

jestjs

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).

like image 544
anon_dcs3spp Avatar asked Oct 18 '25 17:10

anon_dcs3spp


1 Answers

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');
};
like image 151
Estus Flask Avatar answered Oct 20 '25 08:10

Estus Flask



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!