While attempting to refactor my tests that utilize the TestComponentBuilder to comply with the breaking change made in angular2.0.0-beta.2 (currently using angular 2.0.0-beta.6), I end up with this when following the instructions specified in the changelog:
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();
})
}));
});
The final test that utilizes the TestComponentBuilder fails with the following error and stack trace:
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)
The point of failure seems to be when the TestComponentBuilder makes the call to createAsync(SimpleComponent) judging by the above stack trace. What strikes me as odd is that the error is referring to not being able to find the provider for Reflector, which I assume should be covered by the inclusion of angular2-polyfills.js
, angular2.js
and testing.def.js
in my karma.conf.js.
I'm thinking this might be a bug in angular2, but I'm not sure. What makes me think that this is a bug is that I get the impression that with how the DI in angular 2 is encapsulated nothing that I am doing should be able to influence it at this deep of a level. I'd be ecstatic to find out that it is something that I am doing wrong, but the more I dig into this the less I believe this is the case. Any help here would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire