1

base.service.ts

export class BaseService {
    constructor(private http:Http){}
        search(segment: string, param: string){
             //build url
             this.http.get(....){}
        }
    }

my.service.ts

export class MyService {
    constructor(private baseService:Baservice){}
        search(segment: string, param: string){
             //build url
             this.baseService.search('people','1'){}
        }
    }

Base Service is a generic service that will build url and get data from server and return observable.

Now I want to put MyService under test. How can I mock Base Service because the different data sets will be returned with different 'segment' and 'param'

Thanks

Sumo NL
  • 11
  • 1
  • Could you clarify the specific problem; give a [mcve] of how far you've got and what you're stuck on. It's pretty straightforward to inject a mock object with the test bed DI and use `(mock.method as Spy).and...` to configure the fake behaviour. – jonrsharpe Apr 27 '17 at 09:52

0 Answers0