Unit testing a service. Injected service doesn't have access to methods :/


Has anyone tried unit testing a service and not being able to access the methods in the injected service though they are available through proto?

This is my test:

import { TestBed, inject, async } from '@angular/core/testing';
import { Deploy } from '@ionic/cloud-angular';
import { IonicModule, Platform } from 'ionic-angular';
import { EnvironmentModule } from '../app/environment/environment.module';
import { EnvVariables } from '../app/environment/environment.token';
import { MyApp } from '../app/app.component';
import { DeploymentService } from './deployment.service';
import { DeployMock, PlatformMock } from '../mocks';

let envVariables: EnvVariables;

describe('Service: Deployment', () => {
    beforeEach(async(() => {
            declarations: [],
            providers: [
              {provide: Platform, useClass: PlatformMock},
              {provide: Deploy, useClass: DeployMock},
            imports: [

    it('checkForUpdates() should set deploy channel', inject([EnvVariables, DeploymentService, Deploy, Platform], (envVariables: EnvVariables, deploymentService: DeploymentService, deployMock: Deploy, platformMock: Platform) => {
       deploymentService.checkForUpdate().then((resp) => {

I’m trying to unit test DeploymentService. The test fails with this:
TypeError: deploymentService.checkForUpdate(…) is undefined

If I console.log the injected deploymentService I can see that functions are within proto

All the documentation I’ve looked at has implied that I should be able to access that method.

Are the services not being constructed properly? Has anyone else experienced this?


try to call it without this. :wink:


The code I posted is old and something illogical I tried earlier on :P. I’m not currently using this and that’s the error I get. I’ll update my code in the sample.