我正在尝试使用代码覆盖率运行测试用例,但是在import {configure} from "enzyme"
这是Google中一个非常知名的问题。找到了很多答案,但不适用于这些解决方案。
这是我的以下配置:
package.json
{
"name": "project sjp",
"version": "1.0.0",
"description": "project sjp",
"main": "index.js",
"jest1": {
"preset": "jest-puppeteer"
},
"jest": {
"setupFilesAfterEnv": ["<rootDir>/src/app/components/Card/__test__/adapter.js"],
"collectCoverage": true,
"coverageDirectory": "/coverage/",
"collectCoverageFrom": [
"**/*.{js}",
"!**/node_modules/**"
],
"transform": {
"^.+\\.(js)?$": "<rootDir>/node_modules/babel-jest"
},
"verbose": true,
"coverageThreshold": {
"global": {
"branches": 50,
"functions": 50,
"lines": 50,
"statements": 50
}
}
},
"scripts": {
"prestart": "npm run build",
"start": "concurrently --names \"HTTP,BABEL\" -c \"bgBlue.bold,bgMagenta.bold\" \"npm:serve\" \"npm:watch\"",
"serve": "serve -p 3000 ./public -s",
"watch": "npm run build -- -w",
"prebuild": "rm -rf public",
"build": "babel src --out-dir public --copy-files",
"jest": "jest --runInBand --coverage",
"jest:debug": "HEADLESS=false jest --runInBand",
"pretest": "npm run build",
"test": "jest",
"test:debug": "npm run jest:debug",
"prettier": "prettier -c --write \"{src,test}/**/*.js\""
},
"author": "",
"license": "UNLICENSED",
"dependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"babel-jest": "^24.9.0",
"babel-minify": "^0.5.0",
"babel-plugin-minify-builtins": "^0.5.0",
"babel-plugin-minify-dead-code-elimination": "^0.5.0",
"babel-preset-minify": "^0.5.0",
"concurrently": "^4.1.1",
"enzyme": "^3.10.0",
"enzyme-adapter-preact-pure": "^2.0.1",
"husky": "^3.0.1",
"jest": "^24.8.0",
"jest-enzyme": "^7.1.0",
"jest-puppeteer": "^4.3.0",
"preact": "^8.0.0",
"prettier": "^1.18.2",
"puppeteer": "^1.19.0"
},
"browserslist": [
"chrome 75",
"Edge 75",
"FF 67"
],
"husky": {
"hooks1": {
"pre-commit": "npm test",
"pre-push": "npm test"
}
}
}
adapter.js
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-preact-pure';
configure({ adapter: new Adapter });
测试用例
import { h } from 'preact';
import { shallow } from 'enzyme';
import TestComponent from '../../TestComponent.js';
describe('Dashboard Page', () => {
describe('Card Failure', () => {
it('renders <TestComponent /> components', () => {
expect(shallow(<TestComponent />).contains(<div class="flex"></div>)).toBe(true);
});
});
});
我尝试实施从google获得的所有可能的更改,但无法获得解决方案。
请提供您宝贵的意见,这是怎么回事。