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
Videos
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 ·
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
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;
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
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.
Top answer 1 of 2
5
In my case, the solution was:
- Install this package: jest-environment-jsdom
- Add
testEnvironment: 'jest-environment-jsdom'into myjest.config.js; - Run
yarn test(my script:"test": "jest --verbose")
You can see better bellow or the file here in repository ShareBookBR/sharebook-frontend-next
module.exports = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
moduleNameMapper: {
//To include new paths, include also into tsconfig.paths.json
'\\.(scss|sass|css)$': 'identity-obj-proxy',
// '^@/sharebook-components/(.*)$': '<rootDir>/components/$1', //to all paths, ex: @sharebook-components/somegfolder
'^@sharebook-themes': '<rootDir>/src/themes',
'^@sharebook-layouts': '<rootDir>/src/layouts',
'^@sharebook-components': '<rootDir>/src/components',
'^@sharebook-hooks': '<rootDir>/src/hooks',
'^@sharebook-configs': '<rootDir>/src/configs',
'^@sharebook-axios': '<rootDir>/src/axios',
'^@sharebook-utils': '<rootDir>/src/utils'
},
testEnvironment: 'jest-environment-jsdom'
};
2 of 2
1
You can add the testing environment in jest config file just like
module.exports = {
verbose: true,
testEnvironment: 'jsdom',
setupFiles: ['./src/__mocks__/client.js'],
setupFilesAfterEnv: ['./jest.setup.js', '@testing-library/jest-dom/extend-expect'],
moduleDirectories: ['node_modules', 'src'],
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
testEnvironment: 'jsdom'
}
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
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