Testing Angular 4 service without mocking backend -
i need test angular 4 service without mock backend, got no success.
my beforeeach follow:
import { componentfixture, testbed, async } '@angular/core/testing'; import { routerstub } './test-utils/router-stub'; import { mdsnackbarstub } './test-utils/mdsnackbar-stub'; import { mddialogstub } './test-utils/mddialog-stub'; import { httpmodule, http } '@angular/http'; import { router } "@angular/router"; import { mdsnackbar, mddialog } "@angular/material"; import { authservice } './auth.service'; describe('authservice', () => { let authservice: authservice; beforeeach(async(() => { testbed.configuretestingmodule({ imports: [ httpmodule, formsmodule ], providers: [ authservice, { provide: router, useclass: routerstub }, { provide: mdsnackbar, useclass: mdsnackbarstub }, { provide: mddialog, useclass: mddialogstub } ] }).compilecomponents().then((done) => { this.authservice = testbed.get(authservice); this.authservice.login('myusername', 'mypassword'); }); })); });
..but reason, there no way http call api. know service working because it's ok when manually tested. believe testbed providing mocked version of http.
i want because need have authservice logged tests need. authservice holding token information user , data.
may give me directions or point me working example test angular 4 service only?
thanks.
Comments
Post a Comment