angular e2e testing : how to test Service inject(use) another services

前端 未结 1 1777
离开以前
离开以前 2021-01-26 08:14

i\'m trying to test my service with e2e test angular 7, my problem is i don\'t know how to do that:

it\'s my service, (the methode return Observable):



        
1条回答
  •  佛祖请我去吃肉
    2021-01-26 09:11

    So the purpose of the e2e testing is to actually try out your app in it's build form, basically you have done a

    ng build

    on your application where you then afterwards host locally(you can do it externally aswell) that build you just created.

    So basically you service is included in those bundles(more precise in your main bundle) so you dont need to setup any configs instead start testing your app with the protractor api with browser and so on. So your test file could look more like this on when looking at your question:

      describe('workspace-project App', () => {
       let page: AppPage;
       this.chronoInfo = new ALChrono(); //it's a class
    
       beforeEach(() => {
         page = new AppPage();
       });
    
       it('should display welcome message', () => {
         page.navigateTo();
         expect(page.getParagraphText()).toEqual('Welcome to MyProject!');
       });
      }
    

    So the code including the service test should include in your unit-testing If you are not sure how protractor works I suggest you to read up more on the documentation on how the setup works.

    0 讨论(0)
提交回复
热议问题