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


#1

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(() => {
 
        TestBed.configureTestingModule({
 
            declarations: [],
            providers: [
              {provide: Platform, useClass: PlatformMock},
              {provide: Deploy, useClass: DeployMock},
              DeploymentService
            ],
            imports: [
                EnvironmentModule
            ]
 
        });
 
    }));
 

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

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?


#2

try to call it without this. :wink:


#3

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.