[英]ERROR in ./src/polyfills.ts Module not found: Error: Can't resolve 'zone.js/dist/zone'
[英]ERROR in Entry module not found: Error: Can't resolve /src/test.ts
我正在嘗試通過ng test
為我的 Angular 2 應用程序運行單元測試,但我不斷收到以下錯誤:
ERROR in Entry module not found: Error: Can't resolve
'/Users/username/Dev/dashboard/src/test.ts' in '/Users/username/Dev/dashboard/node_modules/@angular/cli/models/webpack-configs'
28 07 2017 15:18:35.337:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
28 07 2017 15:18:35.441:INFO [launcher]: Trying to start Chrome again (1/2).
28 07 2017 15:19:35.447:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
28 07 2017 15:19:35.587:INFO [launcher]: Trying to start Chrome again (2/2).
Angular CLI 版本(npm 更新后): @angular/cli: 1.2.6
和 Node 版本是: node: 8.0.0
其他命令: ng build -prod
和: ng serve
工作正常,沒有錯誤,我可以在瀏覽器上訪問該應用程序。
我必須提到的一件事是,幾天前,我確實從所有方法中刪除了文件夾中的所有.spec.ts
文件:
describe(), beforeEach(), it()
找不到。 經過搜索,我發現刪除它們時應用程序不會中斷,但今天我再次創建它們以運行應用程序的單元測試。
有什么想法嗎?
我和你有同樣的問題,我認為你的test.ts
文件丟失了,這是它的內容:
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/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.
// tslint:disable-next-line:only-arrow-functions
__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();
只需將其保存在app/src/test.ts
並重新運行ng test
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.