Angularjs 失败:没有反射器的提供程序!在带有karma的angular2中运行测试时出错
在尝试重构我的测试时,我使用TestComponentBuilder来遵守angular2.0.0-beta.2(目前使用angular2.0.0-beta.6)中所做的突破性更改,在遵循更改日志中指定的说明时,我最终得到了以下结果:Angularjs 失败:没有反射器的提供程序!在带有karma的angular2中运行测试时出错,angularjs,testing,dependency-injection,angular,Angularjs,Testing,Dependency Injection,Angular,在尝试重构我的测试时,我使用TestComponentBuilder来遵守angular2.0.0-beta.2(目前使用angular2.0.0-beta.6)中所做的突破性更改,在遵循更改日志中指定的说明时,我最终得到了以下结果: import{ it, xit, expect, describe, injectAsync, TestComponentBuilder, setBaseTestProviders } from 'angular2/testing';
import{
it,
xit,
expect,
describe,
injectAsync,
TestComponentBuilder,
setBaseTestProviders
} from 'angular2/testing';
import {
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS
} from 'angular2/platform/testing/browser';
import {Component} from "angular2/core";
@Component({
selector: 'nope',
template: `hello`,
})
class SimpleComponent {
sayHello() {
return "hello"
}
}
describe('Simple Component', () => {
setBaseTestProviders(TEST_BROWSER_APPLICATION_PROVIDERS, TEST_BROWSER_PLATFORM_PROVIDERS);
it('should recognize a simple component', () => {
expect(SimpleComponent).not.toBeNull();
expect(SimpleComponent).not.toBeUndefined();
});
it('should get response from sayHello method', () => {
const simpleComponent = new SimpleComponent();
expect(simpleComponent.sayHello()).toEqual("hello")
});
it('should render simple component', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb.createAsync(SimpleComponent).then(fix => {
fix.detectChanges()
const compiled = fix.debugElement.nativeElement;
expect(compiled).toBeDefined();
})
}));
});
使用TestComponentBuilder的最终测试失败,出现以下错误和堆栈跟踪:
Failed: No provider for Reflector! (DynamicComponentLoader -> Compiler -> RuntimeCompiler -> TemplateCompiler -> TemplateParser -> Parser -> Reflector)
Error: DI Exception
at NoProviderError.BaseException [as constructor] (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:7351:21)
at NoProviderError.AbstractProviderError [as constructor] (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:1649:14)
at new NoProviderError (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:1673:14)
at Injector._throwOrNull (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11547:15)
at Injector._getByKeyDefault (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11592:19)
at Injector._getByKey (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11540:21)
at Injector._getByDependency (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11528:21)
at Injector._instantiate (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11424:32)
at Injector._instantiateProvider (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11395:21)
at Injector._new (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11385:19)
at InjectorDynamicStrategy.getObjByKeyId (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11263:42)
at Injector._getByKeyDefault (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11586:33)
at Injector._getByKey (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11540:21)
at Injector._getByDependency (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11528:21)
at Injector._instantiate (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11423:32)
at Injector._instantiateProvider (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11395:21)
at Injector._new (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11385:19)
at InjectorDynamicStrategy.getObjByKeyId (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11263:42)
at Injector._getByKeyDefault (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11586:33)
at Injector._getByKey (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11540:21)
at Injector._getByDependency (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11528:21)
at Injector._instantiate (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11425:32)
at Injector._instantiateProvider (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11395:21)
at Injector._new (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11385:19)
at InjectorDynamicStrategy.getObjByKeyId (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11263:42)
at Injector._getByKeyDefault (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11586:33)
at Injector._getByKey (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11540:21)
at Injector._getByDependency (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11528:21)
at Injector._instantiate (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11423:32)
at Injector._instantiateProvider (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11395:21)
at Injector._new (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11385:19)
at InjectorDynamicStrategy.getObjByKeyId (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11263:42)
at Injector._getByKeyDefault (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11586:33)
at Injector._getByKey (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11540:21)
at Injector._getByDependency (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11528:21)
at Injector._instantiate (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11423:32)
at Injector._instantiateProvider (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11395:21)
at Injector._new (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11385:19)
at InjectorDynamicStrategy.getObjByKeyId (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11263:42)
at Injector._getByKeyDefault (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11586:33)
at Injector._getByKey (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11540:21)
at Injector._getByDependency (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11528:21)
at Injector._instantiate (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11423:32)
at Injector._instantiateProvider (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11395:21)
at Injector._new (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11385:19)
at InjectorDynamicStrategy.getObjByKeyId (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11263:42)
at Injector._getByKeyDefault (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11586:33)
at Injector._getByKey (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11540:21)
at Injector.get (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:11340:19)
at TestComponentBuilder.createAsync (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/testing.dev.js:848:29)
at eval (/Users/my-username/projects/myproject/myproject-module/spec/module-form.spec.js:54:32)
at FunctionWrapper.apply (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2.js:327:17)
at FunctionWithParamTokens.execute (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/testing.dev.js:1919:37)
at TestInjector.execute (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/testing.dev.js:1864:17)
at Object.<anonymous> (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/testing.dev.js:1978:44)
at Object.eval (/Users/my-username/projects/myproject/myproject-module/spec/example.spec.js:5:9)
at /Users/my-username/projects/myproject/myproject-module/karma.shim.js:55:32
at Zone.run (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:1243:24)
at zoneBoundFn (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:1220:26)
at lib$es6$promise$$internal$$tryCatch (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:468:17)
at lib$es6$promise$$internal$$invokeCallback (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:480:18)
at lib$es6$promise$$internal$$publish (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:451:12)
at /Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:123:10
at Zone.run (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:1243:24)
at zoneBoundFn (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:1220:26)
at lib$es6$promise$asap$$flush (/Users/my-username/projects/myproject/myproject-module/node_modules/angular2/bundles/angular2-polyfills.js:262:10)
失败:没有反射器的提供程序!(DynamicComponentLoader->Compiler->RuntimeCompiler->TemplateCompiler->TemplateParser->Parser->Reflector)
错误:DI异常
在NoProviderError.BaseException[作为构造函数](/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:7351:21)
在NoProviderError.AbstractProviderError[作为构造函数](/Users/my username/projects/myproject/myproject模块/node_模块/angular2/bundles/angular2.js:1649:14)
在新的NoProviderError(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:1673:14)
在Injector.\u throwOrNull(/Users/my username/projects/myproject/myprojectmodule/node\u modules/angular2/bundles/angular2.js:11547:15)
在Injector.\u getByKeyDefault(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11592:19)
在Injector._getByKey(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11540:21)
在Injector.\u getByDependency(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11528:21)
在Injector._实例化(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11424:32)
在Injector.\u实例化Provider(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11395:21)
在Injector._new(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11385:19)
位于InjectorDynamicStrategy.getObjByKeyId(/Users/my username/projects/myproject/myproject模块/node_模块/angular2/bundles/angular2.js:11263:42)
在Injector.\u getByKeyDefault(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11586:33)
在Injector._getByKey(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11540:21)
在Injector.\u getByDependency(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11528:21)
在Injector._实例化(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11423:32)
在Injector.\u实例化Provider(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11395:21)
在Injector._new(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11385:19)
位于InjectorDynamicStrategy.getObjByKeyId(/Users/my username/projects/myproject/myproject模块/node_模块/angular2/bundles/angular2.js:11263:42)
在Injector.\u getByKeyDefault(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11586:33)
在Injector._getByKey(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11540:21)
在Injector.\u getByDependency(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11528:21)
在Injector._实例化(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11425:32)
在Injector.\u实例化Provider(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11395:21)
在Injector._new(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11385:19)
位于InjectorDynamicStrategy.getObjByKeyId(/Users/my username/projects/myproject/myproject模块/node_模块/angular2/bundles/angular2.js:11263:42)
在Injector.\u getByKeyDefault(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11586:33)
在Injector._getByKey(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11540:21)
在Injector.\u getByDependency(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11528:21)
在Injector._实例化(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11423:32)
在Injector.\u实例化Provider(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11395:21)
在Injector._new(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11385:19)
位于InjectorDynamicStrategy.getObjByKeyId(/Users/my username/projects/myproject/myproject模块/node_模块/angular2/bundles/angular2.js:11263:42)
在Injector.\u getByKeyDefault(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11586:33)
在Injector._getByKey(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11540:21)
在Injector.\u getByDependency(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:11528:21)
在Injector._实例化(/Users/my username/projects/myproject/myproject module/node_modules/angular2/bundles/angular2.js:11423:32)
在Injector.\u实例化Provider(/Users/my username/projects/myproject/myproject module/node\u modules/angular2/bundles/angular2.js:113