angular - service (which have dependencies) unit tests with angular2 -
i'm starting angular2
unit tests , running problems. have service accepts parameters applicationref
, componentresolver
service uses componentresolver
load component dynamically. question how can pass in unit tests service above parameters?
does example you:
import {component, provide} '@angular/core'; import {componentfactory} '@angular/core/src/linker/component_factory'; import {componentresolver, reflectorcomponentresolver} '@angular/core/src/linker/component_resolver'; import {reflectioninfo, reflector} '@angular/core/src/reflection/reflection'; import {aftereach, beforeeach, beforeeachproviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} '@angular/core/testing/testing_internal'; import {asynctestcompleter} '@angular/core/testing/testing_internal'; import {console} '../../src/console'; class dummyconsole implements console { log(message: string) {} warn(message: string) {} } export function main() { describe('compiler', () => { var somecompfactory: /** todo #9100 */; var compiler: componentresolver; beforeeach(() => { somecompfactory = new componentfactory(null, null, null); reflector.registertype(somecomponent, new reflectioninfo([somecompfactory])); compiler = new reflectorcomponentresolver(new dummyconsole()); }); it('should read template annotation', inject([asynctestcompleter], (async: asynctestcompleter) => { compiler.resolvecomponent(somecomponent).then((compfactory: componentfactory<any>) => { expect(compfactory).tobe(somecompfactory); async.done(); return null; }); })); it('should throw when given string', inject([asynctestcompleter], (async: asynctestcompleter) => { compiler.resolvecomponent('somestring').catch((e) => { expect(e.message).tocontain('cannot resolve component using \'somestring\'.') async.done(); }); })); }); } class somecomponent {}
Comments
Post a Comment