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

Check if the code is running in Jest

JavaScript

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

TypeScript

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