I am running a cesium project in an angular environment. For the most part, things work fairly well. However, when trying to make unit tests in jasmine, we just can’t seem to get any coverage for any of the code that has to do with the cesium viewer.
I have a method that is called during ngOnInit to create a new viewer.
createMap() {
this.viewer = new Viewer('cesiumContainer, {
imageryProvider = new TileMapServiceImageryProvider({
url: buildModuleUrl (‘Assets/Textures/NaturalEarthII’),
}),
});
}
There are few functions in this component that also operate (add entities, change the selected entity, things like that) that call this.viewer and they all work fine when the app runs.
Now, in our .spec, any time we try to get coverage on anything that relies on the this.viewer… portion of the component, we just don’t get coverage. For example:
it(‘should create the component’, () => {
expect(component).toBeTruthy();
});
runs just fine. However, the coverage fails because it doesn’t create the viewer. My understanding is that this flow should go (from spec) component gets created is compileComponents calls ngOnInit() calls createMap() => this.viewer = new Viewer(…);
The fact that this test passes suggests to me that it did all things. But again, the coverage says that this.viewer = new Viewer(…) line never gets hit. I’m not sure what best practices are here or if I’m missing something simple. But basically any line that has ‘this.viewer…’ doesn’t get coverage. We’re a small team and all of us are stumped. Any help would be appreciated.