使用Angular2.0.0-rc.5
我试图运行下面的试验,但在接收到错误发现“DynamicTestModule”没有NgModule元数据:在单元测试
Error: No NgModule metadata found for 'DynamicTestModule'. (line 29)
这DynamicTestModule
似乎是角本身的一部分,而不是一个模块我在我的项目具有一定的参考,也可以在文档页面找到angular.io
import {inject, async, TestBed} from '@angular/core/testing';
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
describe('AuthService',() => {
beforeEach(() => {
TestBed.initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
).configureTestingModule({
imports: [
{ngModule: CommonModule, providers: [
... // overrides for testing
]}
]});
});
it('should get and set a token saved in storage', inject([AuthService], (instance: AuthService) => {
instance.token = 'test-token';
expect(instance.token).toEqual('test-token');
}));
});
搜索谷歌的错误信息返回任何结果,他们的changelog不会在本例中提到这一点。
有没有人看到这个具体的错误,并知道发生了什么,或者你可以提供一个使用内置的DI测试服务的例子2.0.0-rc.5
没有这个结果的错误?
[没有迹象表明模块](https://angular.io/docs/ts/latest/api/core/index/NgModuleMetadata-class.html#!#imports-anchor)可以是一个普通的对象。像'{imports:[CommonModule],providers:[...]}'应该可以工作,不是吗? – estus
@estus'imports'语句需要一个'Array'。我正在传递['ModuleWithProviders'](https://angular.io/docs/ts/latest/api/core/index/ModuleWithProviders-interface.html),因此语法是有效的。 –
SnareChops