繁体   English   中英

找不到条目模块中的错误:错误:无法解析/src/test.ts

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM