angular - Mock or override extended class in angular2 -


hello every body have problems angular2 unit tests. can me?
have class

export class postcodeapiservice extends apiservice {      constructor(http: http, auth: authservice) {      super(http, auth);    }        getpostcodes(filterobject) {      return super.post('postcodes/filter', filterobject );    }  }

export class apiservice {        constructor(private http: http) {    }      post(url, payload: any) {      return new observable((observer) => {          this.http.post(`someurl/${url}`, payload)            .map((res: response) => res.json())            .catch((error: any) => {              return observable.throw(error || `server error ${url}`);            })            .subscribe((data) => {              observer.next(data);            });      });    }      }

how can mock of apiservice.post() function?

my spec file this

describe('postcodeapiservice', () => {        beforeeach(() => {      testbed.configuretestingmodule({        providers: [          postcodeapiservice,          http,          connectionbackend,          authservice,          userservice        ],        imports: [          httpmodule        ]      });    });      it('should ...', inject([postcodeapiservice], (service: postcodeapiservice) => {      // how ovveride post method ?    }));              });

i grateful if me thing. attention!

create mock class:

    class postcodeapiservicemock extends postcodeapiservice {       post(url, payload: any) {         //       }     } 

and provide with

    { provide: postcodeapiservce, useclass: postcodeapiservicemock } 

you can find example here:

https://angular.io/guide/testing#test-a-routed-component


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -