caution
Jest ships with experimental support for Browser Mode. The implementation may have bugs and lack features.
Multiple Browsers and Mixed Projects
Multiple Browsers
Run the same tests across multiple browsers using instances:
- JavaScript
- TypeScript
jest.config.js
const {defineConfig} = require('jest');
module.exports = defineConfig({
browserMode: {
enabled: true,
provider: 'playwright',
headless: true,
instances: [
{browser: 'chromium'},
{browser: 'firefox'},
{browser: 'webkit'},
],
},
});
jest.config.ts
import {defineConfig} from 'jest';
export default defineConfig({
browserMode: {
enabled: true,
provider: 'playwright',
headless: true,
instances: [
{browser: 'chromium'},
{browser: 'firefox'},
{browser: 'webkit', viewport: {width: 1280, height: 720}},
],
},
});
Each instance can override:
headlessproviderOptionsviewportscreenshotDirectoryscreenshotFailures
Jest runs each browser instance sequentially, reporting results per-browser in the test output.
Mixed Node and Browser Projects
Run browser tests alongside Node-based unit tests using Jest's projects feature:
- JavaScript
- TypeScript
jest.config.js
const {defineConfig} = require('jest');
module.exports = defineConfig({
projects: [
{
displayName: 'unit',
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/unit/**/*.test.ts'],
},
{
displayName: 'browser',
testMatch: ['<rootDir>/tests/browser/**/*.test.ts'],
browserMode: {
enabled: true,
provider: 'playwright',
name: 'chromium',
},
},
],
});
jest.config.ts
import {defineConfig} from 'jest';
export default defineConfig({
projects: [
{
displayName: 'unit',
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/unit/**/*.test.ts'],
},
{
displayName: 'browser',
testMatch: ['<rootDir>/tests/browser/**/*.test.ts'],
browserMode: {
enabled: true,
provider: 'playwright',
name: 'chromium',
},
},
],
});
This allows you to:
- Keep fast unit tests running in Node.js
- Run integration/component tests in a real browser
- Use a single
jestcommand to execute both
Organizing Test Files
A recommended project structure for mixed configurations:
my-project/
├── jest.config.ts
├── tests/
│ ├── unit/ ← Node.js tests (jsdom or node env)
│ │ ├── utils.test.ts
│ │ └── api.test.ts
│ └── browser/ ← Browser mode tests
│ ├── dom.test.ts
│ ├── components.test.ts
│ └── visual.test.ts
└── src/
└── ...
Use testMatch patterns to route files to the correct project configuration.