我有很多在我的项目测试其运行正常,但只要我在它开始无需提供有关问题多的信息打破了文件,添加更多的测试。下面是错误的样子:
{
"message": "An error was thrown in afterAll\nExpected false to be truthy.\n
at http://localhost:9876/_karma_webpack_/webpack:/src/app/views/transfer-order-balance/transfer-order-balance/transfer-order-balance.component.spec.ts:292:47\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:391:1)\n
at ProxyZoneSpec.webpackJsonp../node_modules/zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/proxy.js:129:1)\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:390:1)\nExpected false to be truthy.\n
at http://localhost:9876/_karma_webpack_/webpack:/src/app/views/transfer-order-balance/transfer-order-balance/transfer-order-balance.component.spec.ts:292:47\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:391:1)\n
at ProxyZoneSpec.webpackJsonp../node_modules/zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/proxy.js:129:1)\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:390:1)\nExpected true to be falsy.\n
at http://localhost:9876/_karma_webpack_/webpack:/src/app/views/transfer-order-balance/transfer-order-balance/transfer-order-balance.component.spec.ts:291:73\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:391:1)\n
at ProxyZoneSpec.webpackJsonp../node_modules/zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/proxy.js:129:1)\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:390:1)\nExpected false to be truthy.\n
at http://localhost:9876/_karma_webpack_/webpack:/src/app/views/transfer-order-balance/transfer-order-balance/transfer-order-balance.component.spec.ts:292:47\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:391:1)\n
at ProxyZoneSpec.webpackJsonp../node_modules/zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/proxy.js:129:1)\n
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:390:1)"
我的测试看起来如下:
it('should display provided error message', () => {
component.message = 'Error message sent from other component';
fixture.detectChanges();
const errorElement: HTMLElement = fixture.nativeElement;
const errorMessage = errorElement.querySelector('p');
expect(errorMessage.textContent).toContain(component.message);
});
如果我有不同的消息再次添加类似的测试未能在PhantomJS执行,但在Chrome上正常工作。
我的package.json看起来像下面
{
"name": "@coreuipro/angular",
"version": "1.0.8",
"description": "Bootstrap 4 Admin Template",
"author": "Łukasz Holeczek",
"homepage": "http://coreui.io/pro/",
"copyright": "Copyright 2017 creativeLabs Łukasz Holeczek",
"license": "http://coreui.io/pro/license/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@agm/core": "1.0.0-beta.2",
"@angular/animations": "5.2.0",
"@angular/common": "5.2.0",
"@angular/compiler": "5.2.0",
"@angular/core": "5.2.0",
"@angular/forms": "5.2.0",
"@angular/http": "5.2.0",
"@angular/platform-browser": "5.2.0",
"@angular/platform-browser-dynamic": "5.2.0",
"@angular/router": "5.2.0",
"@angular/upgrade": "5.2.0",
"angular-calendar": "0.23.2",
"angular-webstorage-service": "^1.0.2",
"angular2-datatable": "0.6.0",
"angular2-ladda": "1.2.3",
"angular2-text-mask": "8.0.4",
"angular2-toaster": "4.0.1",
"bootstrap": "4.0.0-beta.3",
"brace": "0.11.0",
"chart.js": "2.7.1",
"codemirror": "5.33.0",
"core-js": "2.5.3",
"dragula": "3.7.2",
"flag-icon-css": "2.9.0",
"font-awesome": "^4.7.0",
"keycloak-angular": "^1.2.5",
"keycloak-js": "^3.4.3",
"lodash": "^4.17.5",
"moment": "2.20.1",
"ng-multiselect-dropdown": "^0.1.6",
"ng-select": "1.0.0-rc.3",
"ng2-ace-editor": "0.3.4",
"ng2-charts": "1.6.0",
"ng2-dragula": "1.5.0",
"ngx-bootstrap": "2.0.0-rc.0",
"ngx-pagination": "^3.1.1",
"ngx-quill": "2.0.4",
"rxjs": "5.5.6",
"simple-line-icons": "^2.4.1",
"spinkit": "1.2.5",
"ts-helpers": "1.1.2",
"zone.js": "^0.8.29"
},
"devDependencies": {
"@angular/cli": "1.7.3",
"@angular/compiler-cli": "5.2.0",
"@angular/language-service": "5.2.0",
"@types/jasmine": "2.8.3",
"@types/jasminewd2": "2.0.3",
"@types/node": "9.3.0",
"codelyzer": "4.0.2",
"jasmine-core": "^2.99.1",
"jasmine-spec-reporter": "4.2.1",
"karma": "2.0.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "1.3.3",
"karma-jasmine": "1.1.1",
"karma-jasmine-html-reporter": "0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"phantomjs-prebuilt": "^2.1.16",
"protractor": "5.2.2",
"ts-node": "4.1.0",
"tslint": "5.9.1",
"typescript": "2.5.3"
}
}
我见过类似这种情况发生的情况下的问题,你有异步但外面跑一个异步区的测试。他们并不总是一致的失败,它可以使调试起来非常困难。我建议在寻找可能被异步运行的测试,并确保他们正确设置来处理。