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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -