在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Install Jest1、install jest dependencies
2、jest.config.js module.exports = { "roots": [ "<rootDir>/src" ], "transform": { "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] } 3、test jest foo.ts export const sum = (...args) => args.reduce((acc, val) => acc+val, 0) foo.test.ts import {sum } from "./foo"; test("basic", () => {expect(sum()).toBe(0)})
test("basic begin", () => {expect(sum(1,2,3)).toBe(6)})
Install Enzyme1、install enzyme dependencies
2、configue enzyme setup-test.ts import { configure } from 'enzyme'; import * as Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() }); 3、update jest.config.js module.exports = { "roots": [ "<rootDir>/src" ], "setupFileAfterEnv": ["<rootDir>/setup-test.ts"] "transform": { "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", "snapshotSerializers": ["enzyme-to-json/serializer"], "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] } 4、update tsconfig.js "exclude": **/*.test.ts""
|
请发表评论