🌐
Jest
jestjs.io › test environment
Test Environment · Jest
May 7, 2026 - To have more fine-grained control, you can use docblock pragmas to specify environment for specific files. Docblock pragmas are comments that start with @jest-environment and are followed by the environment name: ... Jest allows you to extend the built-in environments, such as NodeEnvironment or JSDOMEnvironment, to create your own custom environment.
🌐
npm
npmjs.com › package › jest-environment-node
jest-environment-node - npm
May 8, 2026 - Latest version: 30.4.1, last published: 25 days ago. Start using jest-environment-node in your project by running `npm i jest-environment-node`. There are 1186 other projects in the npm registry using jest-environment-node.
      » npm install jest-environment-node
    
Published   May 08, 2026
Version   30.4.1
🌐
Jest
jestjs.io › environment variables
Environment Variables · Jest
May 7, 2026 - Jest sets the following environment variables: Set to 'test' if it's not already set to something else. Each worker process is assigned a unique id (index-based that starts with 1). This is set to 1 for all tests when runInBand is set to true. NODE_ENV ·
🌐
Testing JavaScript
testingjavascript.com › lessons › jest-configure-jest-s-test-environment-for-testing-node-or-browser-code
Configure Jest’s Test Environment for Testing Node or Browser Code
In our application we’re testing code that should run in the browser, but Jest is intended to test JavaScript that runs in the browser or in node. Let’s create a custom jest config file so we can customize the test environment.
🌐
Jest
jestjs.io › configuring jest
Configuring Jest · Jest
May 8, 2026 - Use the <rootDir> string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. ... An alternative API to setting the NODE_PATH env variable, modulePaths is an array of absolute paths to additional locations to search when resolving modules. Use the <rootDir> string token to include the path to your project's root directory. ... Activates native OS notifications for test results. To display the notifications Jest needs node-notifier package, which must be installed additionally:
🌐
Medium
medium.com › @yiqun.rong2 › jest-test-lifecycle-and-test-environment-06cfbf90f612
Jest test lifecycle and test environment | by Rong | Medium
December 3, 2023 - In Jest, the “Test Environment” specifies the environment in which your tests are executed. It defines the global variables that are available and how certain operations, such as timers and DOM manipulation, are handled. Jest provides different environments to cater to different needs, typically for Node.js or browser-like environments.
🌐
npm
npmjs.com › package › @jest › environment
@jest/environment - npm
September 1, 2025 - Latest version: 30.2.0, last published: 2 months ago. Start using @jest/environment in your project by running `npm i @jest/environment`. There are 72 other projects in the npm registry using @jest/environment.
      » npm install @jest/environment
    
Published   Sep 28, 2025
Version   30.2.0
🌐
Stack Overflow
stackoverflow.com › questions › 68627205 › use-jest-inside-jest-test-environment
Use jest inside Jest Test Environment - javascript
const NodeEnvironment = require('jest-environment-node'); const { lumigo } = require('../../src/services/lumigo'); class TestEnvironment extends NodeEnvironment { async setup() { await super.setup(); jest.mock('../../src/services/lumigo'); lumigo.trace = jest.fn((func) => func); } async teardown() { await super.teardown(); } getVmContext() { return super.getVmContext(); } } module.exports = TestEnvironment;
Find elsewhere
🌐
GitHub
github.com › jestjs › jest › issues › 6634
@jest-environment node not working · Issue #6634 · jestjs/jest
July 5, 2018 - /** * @jest-environment node */ import { URL } from './config'; describe('Config on NodeJS environment', () => { test('it should be a relative url', () => { expect(URL).toBeFalsy(); }); });
Author   jestjs
🌐
Edge Runtime
edge-runtime.vercel.app › packages › jest-environment
Edge Runtime Jest Environment | Edge Runtime
Jest enables you to define the test environment through a code comment (opens in a new tab) or as a CLI option (opens in a new tab). ... // jest --env node // ✅ Pass it('should return the correct value', () => { let val = eval('2 + 2') ...
🌐
GitHub
github.com › jestjs › jest › issues › 12573
[Feature]: Allow `@jest-environment` pragma to be below other comments · Issue #12573 · jestjs/jest
March 12, 2022 - 🚀 Feature Proposal Allow the /** * @jest-environment jsdom */ To not be strictly the first comment node. Motivation Docusaurus has a very strict eslint header config that only allows: /** * Copyright (c) Facebook, Inc. and its affiliates...
Author   jestjs
🌐
Stack Overflow
stackoverflow.com › questions › 73865763 › use-jest-environment-jsdom-and-jest-environment-node-both-in-the-same-project
Use @jest-environment jsdom and @jest-environment node both in the same project [Jest-ReactJS]
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { preset: 'ts-jest', testEnvironment: 'node' }; I have tried below approach, but it didn't work in my experience. /** * @jest-environment jsdom */ test('use jsdom in this test file', () => { const element = document.createElement('div'); expect(element).not.toBeNull(); }); /** * @jest-environment node */ test('do not use jsdom in this test file', () => { console.log(window); // this will fail as node doesn't have a window object });
🌐
jsDocs.io
jsdocs.io › package › jest-environment-node
jest-environment-node@30.2.0 - jsDocs.io
March 10, 2026 - @jest/environment · @jest/fake-timers · @jest/types · @types/node · jest-mock · jest-util · jest-validate · @jest/test-utils · clsx · No peer dependencies. To add a badge like this oneto your package's README, use the codes available below. You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/jest-environment-node.
🌐
Yarn
yarnpkg.com › package
Yarn
Yarn is a package manager that doubles down as project manager. Whether you work on simple projects or industry monorepos, whether you're an open source developer or an enterprise user, Yarn has your back · First package manager built specifically around workspaces, Yarn lets you split your ...
🌐
GitHub
github.com › capricorn86 › happy-dom › wiki › Jest-Environment
Jest Environment · capricorn86/happy-dom Wiki
September 28, 2025 - npm install --save-dev @jest/environment @jest/fake-timers @jest/types @jest/mock @jest/util @happy-dom/jest-environment · Jest uses node as test environment by default.
Author   capricorn86
🌐
Ken Muse
kenmuse.com › blog › crash-course-jest-test-environments-with-typescript
A Crash Course on Jest TestEnvironments with TypeScript - Ken Muse
August 24, 2024 - The test environment that will be used for testing. The default environment in Jest is a Node.js environment.
🌐
GitHub
github.com › jestjs › jest › issues › 3280
@jest-environment jsdom not working · Issue #3280 · jestjs/jest
April 11, 2017 - I'd like to report a bug. What is the current behavior? When setting the jest environment to node in the package.json and using the @jest-environment jsdom docblock in a UI test, jsdom is not a...
Author   jestjs