我使用 Jest 来测试一个有棱角的应用程序,它需要很长的时间来运行简单的测试,我似乎不能弄清楚为什么。
我在 package.json
中的笑话设置:
"jest": {
"modulePaths": [
"<rootDir>/src",
"<rootDir>/node_modules"
],
"testPathIgnorePatterns": [
".git/.*",
"node_modules/.*"
],
"transformIgnorePatterns": [
"node_modules/.*",
".*\\.js"
],
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.js",
"preset": "jest-preset-angular",
"testEnvironment": "jsdom",
"testRegex": "src/app/.*\\.spec\\.ts$",
"moduleFileExtensions": [
"ts",
"js",
"json"
],
"verbose": true,
"cacheDirectory": ".jest-cache",
"coveragePathIgnorePatterns": [
".*\\.(shim\\.ngstyle|ngfactory)\\.ts"
],
"globals": {
"ts-jest": {
"tsConfigFile": "./tsconfig.json"
},
"__TRANSFORM_HTML__": true
}
}
我的 Jest 安装文件:
'use strict';
require('core-js/es6/reflect');
require('core-js/es7/reflect');
require('zone.js');
require('zone.js/dist/proxy.js');
require('zone.js/dist/sync-test');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');
require('jest-zone-patch');
const getTestBed = require('@angular/core/testing').getTestBed;
const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing') .platformBrowserDynamicTesting;
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
这是我的简单测试:
fdescribe('RichTextEditorComponent', () => {
it('should be fast', () => {
expect(true).toBeTruthy();
});
});