jest
约 1 分钟阅读
- facebook/jestGitHubfacebook/jestfacebook/jest · 参考 · kulshekhar/ts-jest · Raathigesh/majestic · Zero config GUI for Jest · 可能需 dom 环境执行 · 修改单个 · 修改默认笔记:jest
- 参考
- kulshekhar/ts-jestGitHubkulshekhar/ts-jestfacebook/jest · 参考 · kulshekhar/ts-jest · Raathigesh/majestic · Zero config GUI for Jest · 可能需 dom 环境执行 · 修改单个 · 修改默认笔记:jest
# typescript
npm i -D jest ts-node ts-jest @types/jest
npx ts-jest config:init
# js
npx jest --initPackagesjestnpm PackagejestNPMts-nodenpm Packagets-nodeNPMts-jestnpm Packagets-jestNPM@types/jestnpm Package@types/jestNPM
配置
jest.config.js
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');
module.exports = {
setupFiles: ['<rootDir>/jest.setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
globals: {
'ts-jest': {
// tsConfig: 'tsconfig.jest.json',
tsConfig: 'tsconfig.json',
},
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
};jest.setup.js
require('dotenv').config();jest.config.ts
import { InitialOptionsTsJest } from 'ts-jest/dist/types';
export default {
preset: 'ts-jest',
testEnvironment: 'node',
} as InitialOptionsTsJest;majestic
- Raathigesh/majesticGitHubRaathigesh/majestic
- Zero config GUI for Jest
npx majesticFAQ
Cannot use import statement outside a module
Node 环境执行
/**
* @jest-environment node
*/ReferenceError: self is not defined
- 可能需 dom 环境执行
- 修改单个
/**
* @jest-environment jsdom
*/- 修改默认
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
};关联信息
反向链接和本文引用的外部资料。
反向链接
- Web Dev FAQ笔记 · jest
| abbr. | stand for | · | iife | Immediately Invoked Function Expression | · 在开发时 assert 错误 · invariant · 早期来自 React, flux
References
GitHub
3 条- facebook/jestgithub.com/facebook/jest
- kulshekhar/ts-jestgithub.com/kulshekhar/ts-jest
- Raathigesh/majesticgithub.com/Raathigesh/majestic