e2e testing angular 7: Failed: Cannot read property 'fetchData' of undefined












1















I'm trying to do some e2e testing for my service in angular 7, the method return Observable, this is my methode:



import { Injectable } from '@angular/core';
import { UrlDecoratorService } from "../../common/url-decorator.service";
import { APIFetcherService } from "../common/api-fetcher.service";
import { Observable } from 'rxjs';
import { IALChrono, ALChrono } from '../../common/IALChrono.interface';

@Injectable()
export class AnnonceChronoDetailService {
private months: string;
constructor(private urlDecoratorService: UrlDecoratorService, private apiFetcher: APIFetcherService) {
}

fetchData(chronoInfo: ALChrono): Observable<any> {
// construct API parameters and URL
var URL: string = this.urlDecoratorService.urlAPIDecorate("AL", "GetAccessChrono");

var params = this.urlDecoratorService.generateParameters({
year: chronoInfo.year,
month: chronoInfo.month,
sortBy: chronoInfo.sortBy,
sortDirection: chronoInfo.sortDirection,
pageNumber: chronoInfo.currentPage,
pageSize: chronoInfo.pageSize
});

return this.apiFetcher.fetchJson(URL, params);
}
}




and this is my test :



import { AppPage } from './app.po';
import { AnnonceChronoDetailService } from '../../src/app/services/annonce-legale/annonce-chrono-detail.service';
import { ALChrono } from '../../src/app/common/IALChrono.interface';
import { APIResponse } from '../../src/app/common/api-response.interface';
import { Observable } from 'rxjs';

describe('workspace-project App', () => {
let page: AppPage;
let service: AnnonceChronoDetailService;
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!');
});


it('#getObservableValue should return value from observable', (done: DoneFn) => {
service.fetchData(this.chronoInfo).subscribe((resp: APIResponse) => {
expect(resp.dataCount).toBe(5);
done();
});
});
});




and this is my terminal error :



DevTools listening on ws://127.0.0.1:53112/devtools/browser/2a1d94b2-ef47-4910-9ee2-e875b615ed45
Jasmine started

workspace-project App
√ should display welcome message
× #getObservableValue should return value from observable
- Failed: Cannot read property 'fetchData' of undefined
at UserContext.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:34:13)
at new ManagedPromise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
at ControlFlow.promise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
at TaskQueue.execute_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
at TaskQueue.executeNext_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
at asyncRun (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
at D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
at <anonymous>
From: Task: Run it("#getObservableValue should return value from observable") in control flow
at ControlFlow.emit (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibevents.js:62:21)
at ControlFlow.shutdown_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2674:10)
at shutdownTask_.MicroTask (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2599:53)
From asynchronous test:
Error
at Suite.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:33:3)
at Object.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:7:1)
at Module._compile (module.js:635:30)
at Module.m._compile (D:Frontnode_modulests-nodesrcindex.ts:439:23)
at Module._extensions..js (module.js:646:10)
at Object.require.extensions.(anonymous function) [as .ts] (D:Frontnode_modulests-nodesrcindex.ts:442:12)

**************************************************
* Failures *
**************************************************

1) workspace-project App #getObservableValue should return value from observable
- Failed: Cannot read property 'fetchData' of undefined

Executed 2 of 2 specs (1 FAILED) in 6 secs.
[10:02:20] I/launcher - 0 instance(s) of WebDriver still running
[10:02:20] I/launcher - chrome #01 failed 1 test(s)
[10:02:20] I/launcher - overall: 1 failed spec(s)
[10:02:20] E/launcher - Process exited with error code 1
An unexpected error occurred: undefined




i want to test the real value of my return methode not like the unit testing, and they don't know my method fetchData.



if you need some more information please tell me😁.



thanks a lot.










share|improve this question



























    1















    I'm trying to do some e2e testing for my service in angular 7, the method return Observable, this is my methode:



    import { Injectable } from '@angular/core';
    import { UrlDecoratorService } from "../../common/url-decorator.service";
    import { APIFetcherService } from "../common/api-fetcher.service";
    import { Observable } from 'rxjs';
    import { IALChrono, ALChrono } from '../../common/IALChrono.interface';

    @Injectable()
    export class AnnonceChronoDetailService {
    private months: string;
    constructor(private urlDecoratorService: UrlDecoratorService, private apiFetcher: APIFetcherService) {
    }

    fetchData(chronoInfo: ALChrono): Observable<any> {
    // construct API parameters and URL
    var URL: string = this.urlDecoratorService.urlAPIDecorate("AL", "GetAccessChrono");

    var params = this.urlDecoratorService.generateParameters({
    year: chronoInfo.year,
    month: chronoInfo.month,
    sortBy: chronoInfo.sortBy,
    sortDirection: chronoInfo.sortDirection,
    pageNumber: chronoInfo.currentPage,
    pageSize: chronoInfo.pageSize
    });

    return this.apiFetcher.fetchJson(URL, params);
    }
    }




    and this is my test :



    import { AppPage } from './app.po';
    import { AnnonceChronoDetailService } from '../../src/app/services/annonce-legale/annonce-chrono-detail.service';
    import { ALChrono } from '../../src/app/common/IALChrono.interface';
    import { APIResponse } from '../../src/app/common/api-response.interface';
    import { Observable } from 'rxjs';

    describe('workspace-project App', () => {
    let page: AppPage;
    let service: AnnonceChronoDetailService;
    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!');
    });


    it('#getObservableValue should return value from observable', (done: DoneFn) => {
    service.fetchData(this.chronoInfo).subscribe((resp: APIResponse) => {
    expect(resp.dataCount).toBe(5);
    done();
    });
    });
    });




    and this is my terminal error :



    DevTools listening on ws://127.0.0.1:53112/devtools/browser/2a1d94b2-ef47-4910-9ee2-e875b615ed45
    Jasmine started

    workspace-project App
    √ should display welcome message
    × #getObservableValue should return value from observable
    - Failed: Cannot read property 'fetchData' of undefined
    at UserContext.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:34:13)
    at new ManagedPromise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
    at ControlFlow.promise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
    at TaskQueue.execute_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
    at TaskQueue.executeNext_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
    at asyncRun (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
    at D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
    at <anonymous>
    From: Task: Run it("#getObservableValue should return value from observable") in control flow
    at ControlFlow.emit (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibevents.js:62:21)
    at ControlFlow.shutdown_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2674:10)
    at shutdownTask_.MicroTask (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2599:53)
    From asynchronous test:
    Error
    at Suite.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:33:3)
    at Object.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:7:1)
    at Module._compile (module.js:635:30)
    at Module.m._compile (D:Frontnode_modulests-nodesrcindex.ts:439:23)
    at Module._extensions..js (module.js:646:10)
    at Object.require.extensions.(anonymous function) [as .ts] (D:Frontnode_modulests-nodesrcindex.ts:442:12)

    **************************************************
    * Failures *
    **************************************************

    1) workspace-project App #getObservableValue should return value from observable
    - Failed: Cannot read property 'fetchData' of undefined

    Executed 2 of 2 specs (1 FAILED) in 6 secs.
    [10:02:20] I/launcher - 0 instance(s) of WebDriver still running
    [10:02:20] I/launcher - chrome #01 failed 1 test(s)
    [10:02:20] I/launcher - overall: 1 failed spec(s)
    [10:02:20] E/launcher - Process exited with error code 1
    An unexpected error occurred: undefined




    i want to test the real value of my return methode not like the unit testing, and they don't know my method fetchData.



    if you need some more information please tell me😁.



    thanks a lot.










    share|improve this question

























      1












      1








      1








      I'm trying to do some e2e testing for my service in angular 7, the method return Observable, this is my methode:



      import { Injectable } from '@angular/core';
      import { UrlDecoratorService } from "../../common/url-decorator.service";
      import { APIFetcherService } from "../common/api-fetcher.service";
      import { Observable } from 'rxjs';
      import { IALChrono, ALChrono } from '../../common/IALChrono.interface';

      @Injectable()
      export class AnnonceChronoDetailService {
      private months: string;
      constructor(private urlDecoratorService: UrlDecoratorService, private apiFetcher: APIFetcherService) {
      }

      fetchData(chronoInfo: ALChrono): Observable<any> {
      // construct API parameters and URL
      var URL: string = this.urlDecoratorService.urlAPIDecorate("AL", "GetAccessChrono");

      var params = this.urlDecoratorService.generateParameters({
      year: chronoInfo.year,
      month: chronoInfo.month,
      sortBy: chronoInfo.sortBy,
      sortDirection: chronoInfo.sortDirection,
      pageNumber: chronoInfo.currentPage,
      pageSize: chronoInfo.pageSize
      });

      return this.apiFetcher.fetchJson(URL, params);
      }
      }




      and this is my test :



      import { AppPage } from './app.po';
      import { AnnonceChronoDetailService } from '../../src/app/services/annonce-legale/annonce-chrono-detail.service';
      import { ALChrono } from '../../src/app/common/IALChrono.interface';
      import { APIResponse } from '../../src/app/common/api-response.interface';
      import { Observable } from 'rxjs';

      describe('workspace-project App', () => {
      let page: AppPage;
      let service: AnnonceChronoDetailService;
      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!');
      });


      it('#getObservableValue should return value from observable', (done: DoneFn) => {
      service.fetchData(this.chronoInfo).subscribe((resp: APIResponse) => {
      expect(resp.dataCount).toBe(5);
      done();
      });
      });
      });




      and this is my terminal error :



      DevTools listening on ws://127.0.0.1:53112/devtools/browser/2a1d94b2-ef47-4910-9ee2-e875b615ed45
      Jasmine started

      workspace-project App
      √ should display welcome message
      × #getObservableValue should return value from observable
      - Failed: Cannot read property 'fetchData' of undefined
      at UserContext.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:34:13)
      at new ManagedPromise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
      at ControlFlow.promise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
      at TaskQueue.execute_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
      at TaskQueue.executeNext_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
      at asyncRun (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
      at D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
      at <anonymous>
      From: Task: Run it("#getObservableValue should return value from observable") in control flow
      at ControlFlow.emit (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibevents.js:62:21)
      at ControlFlow.shutdown_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2674:10)
      at shutdownTask_.MicroTask (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2599:53)
      From asynchronous test:
      Error
      at Suite.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:33:3)
      at Object.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:7:1)
      at Module._compile (module.js:635:30)
      at Module.m._compile (D:Frontnode_modulests-nodesrcindex.ts:439:23)
      at Module._extensions..js (module.js:646:10)
      at Object.require.extensions.(anonymous function) [as .ts] (D:Frontnode_modulests-nodesrcindex.ts:442:12)

      **************************************************
      * Failures *
      **************************************************

      1) workspace-project App #getObservableValue should return value from observable
      - Failed: Cannot read property 'fetchData' of undefined

      Executed 2 of 2 specs (1 FAILED) in 6 secs.
      [10:02:20] I/launcher - 0 instance(s) of WebDriver still running
      [10:02:20] I/launcher - chrome #01 failed 1 test(s)
      [10:02:20] I/launcher - overall: 1 failed spec(s)
      [10:02:20] E/launcher - Process exited with error code 1
      An unexpected error occurred: undefined




      i want to test the real value of my return methode not like the unit testing, and they don't know my method fetchData.



      if you need some more information please tell me😁.



      thanks a lot.










      share|improve this question














      I'm trying to do some e2e testing for my service in angular 7, the method return Observable, this is my methode:



      import { Injectable } from '@angular/core';
      import { UrlDecoratorService } from "../../common/url-decorator.service";
      import { APIFetcherService } from "../common/api-fetcher.service";
      import { Observable } from 'rxjs';
      import { IALChrono, ALChrono } from '../../common/IALChrono.interface';

      @Injectable()
      export class AnnonceChronoDetailService {
      private months: string;
      constructor(private urlDecoratorService: UrlDecoratorService, private apiFetcher: APIFetcherService) {
      }

      fetchData(chronoInfo: ALChrono): Observable<any> {
      // construct API parameters and URL
      var URL: string = this.urlDecoratorService.urlAPIDecorate("AL", "GetAccessChrono");

      var params = this.urlDecoratorService.generateParameters({
      year: chronoInfo.year,
      month: chronoInfo.month,
      sortBy: chronoInfo.sortBy,
      sortDirection: chronoInfo.sortDirection,
      pageNumber: chronoInfo.currentPage,
      pageSize: chronoInfo.pageSize
      });

      return this.apiFetcher.fetchJson(URL, params);
      }
      }




      and this is my test :



      import { AppPage } from './app.po';
      import { AnnonceChronoDetailService } from '../../src/app/services/annonce-legale/annonce-chrono-detail.service';
      import { ALChrono } from '../../src/app/common/IALChrono.interface';
      import { APIResponse } from '../../src/app/common/api-response.interface';
      import { Observable } from 'rxjs';

      describe('workspace-project App', () => {
      let page: AppPage;
      let service: AnnonceChronoDetailService;
      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!');
      });


      it('#getObservableValue should return value from observable', (done: DoneFn) => {
      service.fetchData(this.chronoInfo).subscribe((resp: APIResponse) => {
      expect(resp.dataCount).toBe(5);
      done();
      });
      });
      });




      and this is my terminal error :



      DevTools listening on ws://127.0.0.1:53112/devtools/browser/2a1d94b2-ef47-4910-9ee2-e875b615ed45
      Jasmine started

      workspace-project App
      √ should display welcome message
      × #getObservableValue should return value from observable
      - Failed: Cannot read property 'fetchData' of undefined
      at UserContext.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:34:13)
      at new ManagedPromise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:1077:7)
      at ControlFlow.promise (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2505:12)
      at TaskQueue.execute_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3084:14)
      at TaskQueue.executeNext_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:3067:27)
      at asyncRun (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2974:25)
      at D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:668:7
      at <anonymous>
      From: Task: Run it("#getObservableValue should return value from observable") in control flow
      at ControlFlow.emit (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibevents.js:62:21)
      at ControlFlow.shutdown_ (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2674:10)
      at shutdownTask_.MicroTask (D:Frontnode_modulesprotractornode_modulesselenium-webdriverlibpromise.js:2599:53)
      From asynchronous test:
      Error
      at Suite.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:33:3)
      at Object.<anonymous> (D:Fronte2esrcapp.e2e-spec.ts:7:1)
      at Module._compile (module.js:635:30)
      at Module.m._compile (D:Frontnode_modulests-nodesrcindex.ts:439:23)
      at Module._extensions..js (module.js:646:10)
      at Object.require.extensions.(anonymous function) [as .ts] (D:Frontnode_modulests-nodesrcindex.ts:442:12)

      **************************************************
      * Failures *
      **************************************************

      1) workspace-project App #getObservableValue should return value from observable
      - Failed: Cannot read property 'fetchData' of undefined

      Executed 2 of 2 specs (1 FAILED) in 6 secs.
      [10:02:20] I/launcher - 0 instance(s) of WebDriver still running
      [10:02:20] I/launcher - chrome #01 failed 1 test(s)
      [10:02:20] I/launcher - overall: 1 failed spec(s)
      [10:02:20] E/launcher - Process exited with error code 1
      An unexpected error occurred: undefined




      i want to test the real value of my return methode not like the unit testing, and they don't know my method fetchData.



      if you need some more information please tell me😁.



      thanks a lot.







      angular protractor e2e-testing angular2-observables angular-e2e






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 10:12









      SaadSaad

      247




      247
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You have not created an instance of AnnonceChronoDetailService (just the reference is created), that is why service variable is undefined



          let page: AppPage;
          let service: AnnonceChronoDetailService;
          this.chronoInfo = new ALChrono(); //it's a class

          beforeEach(() => {
          page = new AppPage();
          service = new AnnonceChronoDetailService(); // create service instance
          });





          share|improve this answer
























          • yeah, i try to do that, but the class AnnonceChronoDetailService need parameters like UrlDecoratorService and APIFetcherService, i don't know how to pass it.

            – Saad
            Nov 16 '18 at 10:27













          • If you are simply mocking the method, then you can always pass null to it like service = new AnnonceChronoDetailService(null, null);

            – Amit Chigadani
            Nov 16 '18 at 10:34











          • i do that and i have this problem Failed: Cannot read property 'urlAPIDecorate' of null and i do service = new AnnonceChronoDetailService(new UrlDecoratorService(),null); and i have this problem - Failed: Cannot read property 'fetchJson' of null, and i do that service = new AnnonceChronoDetailService(new UrlDecoratorService(),new APIFetcherService(new Http(new ConnectionBackend(),new RequestOptions()))); and i have this problem - Failed: sessionStorage is not defined

            – Saad
            Nov 16 '18 at 10:48











          • I already said, only if you are mocking the method, then it works. I am not sure how services are injected in e2e testing similar to TestBed.get() in unit testing.

            – Amit Chigadani
            Nov 16 '18 at 10:51











          • thanks you give me the right way to search more.

            – Saad
            Nov 16 '18 at 11:05












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335638%2fe2e-testing-angular-7-failed-cannot-read-property-fetchdata-of-undefined%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You have not created an instance of AnnonceChronoDetailService (just the reference is created), that is why service variable is undefined



          let page: AppPage;
          let service: AnnonceChronoDetailService;
          this.chronoInfo = new ALChrono(); //it's a class

          beforeEach(() => {
          page = new AppPage();
          service = new AnnonceChronoDetailService(); // create service instance
          });





          share|improve this answer
























          • yeah, i try to do that, but the class AnnonceChronoDetailService need parameters like UrlDecoratorService and APIFetcherService, i don't know how to pass it.

            – Saad
            Nov 16 '18 at 10:27













          • If you are simply mocking the method, then you can always pass null to it like service = new AnnonceChronoDetailService(null, null);

            – Amit Chigadani
            Nov 16 '18 at 10:34











          • i do that and i have this problem Failed: Cannot read property 'urlAPIDecorate' of null and i do service = new AnnonceChronoDetailService(new UrlDecoratorService(),null); and i have this problem - Failed: Cannot read property 'fetchJson' of null, and i do that service = new AnnonceChronoDetailService(new UrlDecoratorService(),new APIFetcherService(new Http(new ConnectionBackend(),new RequestOptions()))); and i have this problem - Failed: sessionStorage is not defined

            – Saad
            Nov 16 '18 at 10:48











          • I already said, only if you are mocking the method, then it works. I am not sure how services are injected in e2e testing similar to TestBed.get() in unit testing.

            – Amit Chigadani
            Nov 16 '18 at 10:51











          • thanks you give me the right way to search more.

            – Saad
            Nov 16 '18 at 11:05
















          0














          You have not created an instance of AnnonceChronoDetailService (just the reference is created), that is why service variable is undefined



          let page: AppPage;
          let service: AnnonceChronoDetailService;
          this.chronoInfo = new ALChrono(); //it's a class

          beforeEach(() => {
          page = new AppPage();
          service = new AnnonceChronoDetailService(); // create service instance
          });





          share|improve this answer
























          • yeah, i try to do that, but the class AnnonceChronoDetailService need parameters like UrlDecoratorService and APIFetcherService, i don't know how to pass it.

            – Saad
            Nov 16 '18 at 10:27













          • If you are simply mocking the method, then you can always pass null to it like service = new AnnonceChronoDetailService(null, null);

            – Amit Chigadani
            Nov 16 '18 at 10:34











          • i do that and i have this problem Failed: Cannot read property 'urlAPIDecorate' of null and i do service = new AnnonceChronoDetailService(new UrlDecoratorService(),null); and i have this problem - Failed: Cannot read property 'fetchJson' of null, and i do that service = new AnnonceChronoDetailService(new UrlDecoratorService(),new APIFetcherService(new Http(new ConnectionBackend(),new RequestOptions()))); and i have this problem - Failed: sessionStorage is not defined

            – Saad
            Nov 16 '18 at 10:48











          • I already said, only if you are mocking the method, then it works. I am not sure how services are injected in e2e testing similar to TestBed.get() in unit testing.

            – Amit Chigadani
            Nov 16 '18 at 10:51











          • thanks you give me the right way to search more.

            – Saad
            Nov 16 '18 at 11:05














          0












          0








          0







          You have not created an instance of AnnonceChronoDetailService (just the reference is created), that is why service variable is undefined



          let page: AppPage;
          let service: AnnonceChronoDetailService;
          this.chronoInfo = new ALChrono(); //it's a class

          beforeEach(() => {
          page = new AppPage();
          service = new AnnonceChronoDetailService(); // create service instance
          });





          share|improve this answer













          You have not created an instance of AnnonceChronoDetailService (just the reference is created), that is why service variable is undefined



          let page: AppPage;
          let service: AnnonceChronoDetailService;
          this.chronoInfo = new ALChrono(); //it's a class

          beforeEach(() => {
          page = new AppPage();
          service = new AnnonceChronoDetailService(); // create service instance
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 10:19









          Amit ChigadaniAmit Chigadani

          10.7k53053




          10.7k53053













          • yeah, i try to do that, but the class AnnonceChronoDetailService need parameters like UrlDecoratorService and APIFetcherService, i don't know how to pass it.

            – Saad
            Nov 16 '18 at 10:27













          • If you are simply mocking the method, then you can always pass null to it like service = new AnnonceChronoDetailService(null, null);

            – Amit Chigadani
            Nov 16 '18 at 10:34











          • i do that and i have this problem Failed: Cannot read property 'urlAPIDecorate' of null and i do service = new AnnonceChronoDetailService(new UrlDecoratorService(),null); and i have this problem - Failed: Cannot read property 'fetchJson' of null, and i do that service = new AnnonceChronoDetailService(new UrlDecoratorService(),new APIFetcherService(new Http(new ConnectionBackend(),new RequestOptions()))); and i have this problem - Failed: sessionStorage is not defined

            – Saad
            Nov 16 '18 at 10:48











          • I already said, only if you are mocking the method, then it works. I am not sure how services are injected in e2e testing similar to TestBed.get() in unit testing.

            – Amit Chigadani
            Nov 16 '18 at 10:51











          • thanks you give me the right way to search more.

            – Saad
            Nov 16 '18 at 11:05



















          • yeah, i try to do that, but the class AnnonceChronoDetailService need parameters like UrlDecoratorService and APIFetcherService, i don't know how to pass it.

            – Saad
            Nov 16 '18 at 10:27













          • If you are simply mocking the method, then you can always pass null to it like service = new AnnonceChronoDetailService(null, null);

            – Amit Chigadani
            Nov 16 '18 at 10:34











          • i do that and i have this problem Failed: Cannot read property 'urlAPIDecorate' of null and i do service = new AnnonceChronoDetailService(new UrlDecoratorService(),null); and i have this problem - Failed: Cannot read property 'fetchJson' of null, and i do that service = new AnnonceChronoDetailService(new UrlDecoratorService(),new APIFetcherService(new Http(new ConnectionBackend(),new RequestOptions()))); and i have this problem - Failed: sessionStorage is not defined

            – Saad
            Nov 16 '18 at 10:48











          • I already said, only if you are mocking the method, then it works. I am not sure how services are injected in e2e testing similar to TestBed.get() in unit testing.

            – Amit Chigadani
            Nov 16 '18 at 10:51











          • thanks you give me the right way to search more.

            – Saad
            Nov 16 '18 at 11:05

















          yeah, i try to do that, but the class AnnonceChronoDetailService need parameters like UrlDecoratorService and APIFetcherService, i don't know how to pass it.

          – Saad
          Nov 16 '18 at 10:27







          yeah, i try to do that, but the class AnnonceChronoDetailService need parameters like UrlDecoratorService and APIFetcherService, i don't know how to pass it.

          – Saad
          Nov 16 '18 at 10:27















          If you are simply mocking the method, then you can always pass null to it like service = new AnnonceChronoDetailService(null, null);

          – Amit Chigadani
          Nov 16 '18 at 10:34





          If you are simply mocking the method, then you can always pass null to it like service = new AnnonceChronoDetailService(null, null);

          – Amit Chigadani
          Nov 16 '18 at 10:34













          i do that and i have this problem Failed: Cannot read property 'urlAPIDecorate' of null and i do service = new AnnonceChronoDetailService(new UrlDecoratorService(),null); and i have this problem - Failed: Cannot read property 'fetchJson' of null, and i do that service = new AnnonceChronoDetailService(new UrlDecoratorService(),new APIFetcherService(new Http(new ConnectionBackend(),new RequestOptions()))); and i have this problem - Failed: sessionStorage is not defined

          – Saad
          Nov 16 '18 at 10:48





          i do that and i have this problem Failed: Cannot read property 'urlAPIDecorate' of null and i do service = new AnnonceChronoDetailService(new UrlDecoratorService(),null); and i have this problem - Failed: Cannot read property 'fetchJson' of null, and i do that service = new AnnonceChronoDetailService(new UrlDecoratorService(),new APIFetcherService(new Http(new ConnectionBackend(),new RequestOptions()))); and i have this problem - Failed: sessionStorage is not defined

          – Saad
          Nov 16 '18 at 10:48













          I already said, only if you are mocking the method, then it works. I am not sure how services are injected in e2e testing similar to TestBed.get() in unit testing.

          – Amit Chigadani
          Nov 16 '18 at 10:51





          I already said, only if you are mocking the method, then it works. I am not sure how services are injected in e2e testing similar to TestBed.get() in unit testing.

          – Amit Chigadani
          Nov 16 '18 at 10:51













          thanks you give me the right way to search more.

          – Saad
          Nov 16 '18 at 11:05





          thanks you give me the right way to search more.

          – Saad
          Nov 16 '18 at 11:05




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335638%2fe2e-testing-angular-7-failed-cannot-read-property-fetchdata-of-undefined%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma