Cannot get Code Coverage for new Viewer

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’, () => {
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.

Hey @Pennington :wave: Could you please share your karma configuration file?

Sure, don’t know how to link the file directly, but this is what I’ve got:
// Karma configuration file, see link for more information
// Karma - Configuration File

module.exports = function(config) {
basePath: ‘’,
frameworks: [‘jasmine’, ‘@angular-devkit/build-angular’],
plugins: [
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at Interface: Configuration
// for example, you can disable the random execution with random: false
// or set a specific seed with seed: 4321
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
coverageReporter: {
dir: require(‘path’).join(__dirname, ‘./build/reports/coverage’),
subdir: ‘.’,
reporters: [
{type: ‘html’},
{type: ‘text-summary’},
{type: ‘lcov’},
{type: ‘cobertura’, file: ‘cobertura.txt’},
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: ‘ChromeHeadless’,
flags: [‘–no-sandbox’],
reporters: [‘progress’, ‘kjhtml’],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: [‘Edge’],
singleRun: false,
restartOnFileChange: true,

With your current configuration, I tried to run ng test --code-coverage against this repo and it reported 100% coverage:


I guess it has to do with how you write your unit test and your component. Could you paste the code from both to have a look?