Is there any way to extend global jest test with some custom property? For example, I want implement some logic before test in this way:
test.debug({ /* ... */ }, 'test', () => {
// ...
});
Is there any way to extend global jest test with some custom property? For example, I want implement some logic before test in this way:
test.debug({ /* ... */ }, 'test', () => {
// ...
});
This can be done either in per-test setup file or custom environment, in case a customization needs to interact with the environment on a deeper level:
it.whatever = (whateverArg, ...args) => {
const cb = args[1];
if (cb) {
args[1] = cb.length ?
(done) => { /* do whatever with whateverArg */ return cb(done); } :
() => { /* do whatever with whateverArg */ return cb(); }
}
return it(...args);
};
All arguments need to be passed to it as is, test callback needs to be additionally taken care of because whether a test is considered asynchronous depends on callback function arity.