[Home] >  Misc >  Check if the code is running in Jest

Check if the code is running in Jest

JavaScript version

const isRunningInJest = typeof process !== 'undefined' && process.env.JEST_WORKER_ID !== undefined;

TypeScript version

const isRunningInJest: boolean = typeof process !== 'undefined' && process.env.JEST_WORKER_ID !== undefined;