Angular 2 - Unit testing spy not called
<p>I am testing a component say : export and import files which uses a service called uploadService.ts </p>

<p>uploadService has a method sendFile which is called internally by component method importRules().</p>

<p><strong>uploadService.ts</strong></p>

<pre><code>@Injectable()
export class UploadService {

    constructor(private http: Http, private sharedData: SharedDataService) { }

    sendFile(file: File, groupName?: string): Observable&lt;Response&gt; {
        …
        return this.http.post(url, data, options);
    }
}
</code></pre>

<p><strong>exportImport.components.ts</strong></p>

<pre><code>ImportRules() {
     this.uploadService.sendFile(fileObj, fileName) {
     …
     }
}
</code></pre>

<p>Corresponding spec file 
<strong>exportImport.components.spec.ts</strong></p>

<pre><code>class MockUploadService extends UploadService {
            constructor() {
                super(null, null);
            }

            sendFile(file: File, groupName?: string): Observable&lt;Response&gt; {
                let resObject = new Response(null);
                resObject.status = 200;
                return Observable.of(resObject);
            }
        }
</code></pre>

<p>And in beforeEach I have replaced real service with mock service</p>

<pre><code>it('should import ioc rules',
        async(() =&gt; {
            TestBed
                .compileComponents()
                .then(() =&gt; {
                    let fixture = TestBed.createComponent(TestComponent);
                    // let http = new ConnectionBackend();
                    let exportImportInstance = fixture.debugElement.children[0].componentInstance;
                    let mockReq: MockUploadService = new MockUploadService();
                    exportImportInstance.setGroupName('test');
                    exportImportInstance.setChosenFile('file.json');
                    spyOn(mockReq, 'sendFile');
                    exportImportInstance.importRules();
                    expect(mockReq.sendFile).toHaveBeenCalledWith('file.json', 'test');
                });

        }));
</code></pre>

<p>But on executing the test I am getting error: </p>

<blockquote>
  <p>Expected spy sendFile to have been called with [ 'file.json', 'test' ] but it was never called. </p>
</blockquote>

<p>I am not getting what I am doing wrong here.</p>