Angular 2 Testing with Javascript Library as a dependency -
i'm trying write test component, uses javascript library. therefore declared object on top, make available in typescript. far :-) no i'm trying run test, fails because test doesn't know declared object in component.
how make object available inside test spec?
import { component } '@angular/core'; declare var h: any; @component({ selector: 'fb-root', templateurl: './app.component.html', styleurls: ['./app.component.scss'] }) export class appcomponent { title = 'request vehicle'; test = this.title == this.title; ngoninit(): void { var mapcontainer = document.createelement('div'); var uiview = document.getelementbyid('map-container'); mapcontainer.setattribute('id', 'map'); mapcontainer.setattribute('style', 'width: 100%; height: 100vh; background: grey'); uiview.appendchild(mapcontainer); let platform = new h.service.platform({ app_id: '', app_code: '', usecit: true, usehttps: true }); // obtain default map types platform object: var defaultlayers = platform.createdefaultlayers(); // instantiate (and display) map object: var map = new h.map( document.getelementbyid('map'), defaultlayers.normal.map, { zoom: 10, center: { lat: 53, lng: 18 } }); } } import { testbed, async } '@angular/core/testing'; import { routertestingmodule } '@angular/router/testing'; import { appcomponent } './app.component'; describe('appcomponent', () => { beforeeach(async(() => { testbed.configuretestingmodule({ imports: [ routertestingmodule ], declarations: [ appcomponent ], }).compilecomponents(); })); it('should create app', async(() => { const fixture = testbed.createcomponent(appcomponent); const app = fixture.debugelement.componentinstance; expect(app).tobetruthy(); })); it(`should have title 'request vehicle'`, async(() => { const fixture = testbed.createcomponent(appcomponent); const app = fixture.debugelement.componentinstance; expect(app.title).toequal('request vehicle'); })); it('should render title in h1 tag', async(() => { const fixture = testbed.createcomponent(appcomponent); fixture.detectchanges(); const compiled = fixture.debugelement.nativeelement; expect(compiled.queryselector('h1').textcontent).tocontain('request vehicle'); })); });
Comments
Post a Comment