第一件事:我的项目在分支/develop
上完全正常,测试通过等等。
我创建了一个分支来清理imports
并在每次访问类时使用别名而不是../../../../
。我将它添加到tsconfig.json
中:
"baseUrl": "src",
"paths": {
"@app/*": [
"app/*"
],
"@core/*": [
"app/core/*"
],
"@common/*": [
"app/common/*"
],
"@models/*": [
"app/models/*"
],
"@env/*": [
"environments/*"
],
"@assets/*": [
"assets/*"
]
}
我刚刚完成了测试,但是当使用简单的npm run test
执行测试时,它会做一些类似于thiis的事情,比如karma start ./karma.conf.js --log-level error
,我得到了这个错误:
HeadlessChrome 67.0.3396 (Windows 10.0.0) ERROR
Uncaught Error: Missing: SyncTestZoneSpec
at http://localhost:9876/_karma_webpack_/vendor.bundle.js:270128
我所改变的只是我上面告诉我的,这个错误告诉我什么?
编辑:使用github链接进行更正
通过将zone.js版本更新为0.8.26纠正了此问题,并仅用一行替换了test.ts中的导入:
import 'zone.js/dist/zone-testing';
但是现在我得到了所有测试的错误:
HeadlessChrome 67.0.3396 (Windows 10.0.0) SomeService #getCurrentUser should return user object FAILED
TypeError: Cannot read property 'assertPresent' of undefined
at resetFakeAsyncZone node_modules/@angular/core/@angular/core/testing.es5.js:308:1)
at Object.<anonymous> node_modules/@angular/core/@angular/core/testing.es5.js:1015:1)
at ZoneQueueRunner.webpackJsonp../node_modules/zone.js/dist/zone-testing.js.jasmine.QueueRunner.ZoneQueueRunner.execute node_modules/zone.js/dist/zone-testing.js:437:1)
HeadlessChrome 67.0.3396 (Windows 10.0.0): Executed 120 of 120 (120 FAILED) ERROR (4.725 secs / 4.633 secs)
关于github的相关问题,但目前还没有解决方案。
我的test.ts
的内容:
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import 'zone.js/dist/zone-testing';
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare const __karma__: any;
declare const require: any;
// Prevent Karma from running prematurely.
__karma__.loaded = function () {};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();
发布于 2018-06-28 05:42:45
尝试将zone-testing
导入移到第一批导入之一,如下所示:
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from
'@angular/platform-browser-dynamic/testing';
摘自此错误报告:如果在test.ts中更改导入顺序,则所有测试都失败
https://stackoverflow.com/questions/50950740
复制