object is probably 'undefined' - Mocha Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to run a single test with Mocha?How to increase timeout for a single test case in mochaCode coverage with MochaConfiguring multiple capabilities with promisesMocha ES6 Relative ImportInheriting from Protractor's ElementFinder type without getting typescript warningsXMLHttpRequest undefined, angular mock-ajax does not listen to ajax calls by the source code?Re-initializing helper class after browser restart in protractorprotractor inconsistent results - Failed: script timeout: result was not receivedMy Protractor test is hanging when trying to determine if an element is present

Can anything be seen from the center of the Boötes void? How dark would it be?

Is grep documentation wrong?

Is it fair for a professor to grade us on the possession of past papers?

Using et al. for a last / senior author rather than for a first author

Do wooden building fires get hotter than 600°C?

Around usage results

If a contract sometimes uses the wrong name, is it still valid?

How does the math work when buying airline miles?

Why are the trig functions versine, haversine, exsecant, etc, rarely used in modern mathematics?

How do pianists reach extremely loud dynamics?

What are the out-of-universe reasons for the references to Toby Maguire-era Spider-Man in ITSV

Is there a kind of relay only consumes power when switching?

Fundamental Solution of the Pell Equation

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Significance of Cersei's obsession with elephants?

Generate an RGB colour grid

Crossing US/Canada Border for less than 24 hours

Amount of permutations on an NxNxN Rubik's Cube

Compare a given version number in the form major.minor.build.patch and see if one is less than the other

What is the meaning of the simile “quick as silk”?

Extracting terms with certain heads in a function

Is "Reachable Object" really an NP-complete problem?

How would a mousetrap for use in space work?

What font is "z" in "z-score"?



object is probably 'undefined' - Mocha



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to run a single test with Mocha?How to increase timeout for a single test case in mochaCode coverage with MochaConfiguring multiple capabilities with promisesMocha ES6 Relative ImportInheriting from Protractor's ElementFinder type without getting typescript warningsXMLHttpRequest undefined, angular mock-ajax does not listen to ajax calls by the source code?Re-initializing helper class after browser restart in protractorprotractor inconsistent results - Failed: script timeout: result was not receivedMy Protractor test is hanging when trying to determine if an element is present



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I am using Protractor. The below solution works, but i get this warning:



this.currentTest.state
- error TS2532: Object is possibly 'undefined'
(property) Mocha.Context.currentTest?: Mocha.Test | undefined



How do i fix this warning?



Test file:



const helper = new HelperClass();
afterEach(async ()=>
const state = this.currentTest.state;
await helper.getSource(state);
);


Class File



import browser, from 'protractor';
export class HelperClass

public getSource(state:any)

if (state === 'failed')
browser.driver.getPageSource().then(function (res)
console.log(res);
);












share|improve this question




























    2















    I am using Protractor. The below solution works, but i get this warning:



    this.currentTest.state
    - error TS2532: Object is possibly 'undefined'
    (property) Mocha.Context.currentTest?: Mocha.Test | undefined



    How do i fix this warning?



    Test file:



    const helper = new HelperClass();
    afterEach(async ()=>
    const state = this.currentTest.state;
    await helper.getSource(state);
    );


    Class File



    import browser, from 'protractor';
    export class HelperClass

    public getSource(state:any)

    if (state === 'failed')
    browser.driver.getPageSource().then(function (res)
    console.log(res);
    );












    share|improve this question
























      2












      2








      2








      I am using Protractor. The below solution works, but i get this warning:



      this.currentTest.state
      - error TS2532: Object is possibly 'undefined'
      (property) Mocha.Context.currentTest?: Mocha.Test | undefined



      How do i fix this warning?



      Test file:



      const helper = new HelperClass();
      afterEach(async ()=>
      const state = this.currentTest.state;
      await helper.getSource(state);
      );


      Class File



      import browser, from 'protractor';
      export class HelperClass

      public getSource(state:any)

      if (state === 'failed')
      browser.driver.getPageSource().then(function (res)
      console.log(res);
      );












      share|improve this question














      I am using Protractor. The below solution works, but i get this warning:



      this.currentTest.state
      - error TS2532: Object is possibly 'undefined'
      (property) Mocha.Context.currentTest?: Mocha.Test | undefined



      How do i fix this warning?



      Test file:



      const helper = new HelperClass();
      afterEach(async ()=>
      const state = this.currentTest.state;
      await helper.getSource(state);
      );


      Class File



      import browser, from 'protractor';
      export class HelperClass

      public getSource(state:any)

      if (state === 'failed')
      browser.driver.getPageSource().then(function (res)
      console.log(res);
      );









      protractor mocha






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 18:57









      user6086008user6086008

      84210




      84210






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I think the error occurs because the access to this.currentTest.state happens inside another function: the arrow function passed in to afterEach--flow analysis does not cross function boundaries. Try simply pulling that line outside of the function:



          const helper = new HelperClass();
          afterEach(async ()=>
          const state = this.!currentTest.state;
          await helper.getSource(state);
          );


          Does that change anything?






          share|improve this answer

























          • if i put it outside of the function, i get: Property 'currentTest' does not exist on type 'Suite'. If i put it outside of the describe i get: 'this' implicitly has type 'any' because it does not have a type annotation'.

            – user6086008
            Mar 10 at 10:05











          • Um..... Try this: const helper = new HelperClass(); afterEach(async ()=> await helper.getSource(state); const state = this.!currentTest.state; );

            – C. Peck
            Mar 10 at 10:13












          • I edited my answer because the comment was unreadable. Basically I'm trying to tell it 'yeah, this is undefined, so what'? To avoid the warning and move on.

            – C. Peck
            Mar 10 at 10:17











          • no, it didnt work. I got Multiple variable declarations in the same statement are forbiddents .

            – user6086008
            Mar 10 at 10:32












          • But i seem to have solved it by adding this: any in the function afterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)

            – user6086008
            Mar 10 at 10:35












          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%2f55069374%2fobject-is-probably-undefined-mocha%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














          I think the error occurs because the access to this.currentTest.state happens inside another function: the arrow function passed in to afterEach--flow analysis does not cross function boundaries. Try simply pulling that line outside of the function:



          const helper = new HelperClass();
          afterEach(async ()=>
          const state = this.!currentTest.state;
          await helper.getSource(state);
          );


          Does that change anything?






          share|improve this answer

























          • if i put it outside of the function, i get: Property 'currentTest' does not exist on type 'Suite'. If i put it outside of the describe i get: 'this' implicitly has type 'any' because it does not have a type annotation'.

            – user6086008
            Mar 10 at 10:05











          • Um..... Try this: const helper = new HelperClass(); afterEach(async ()=> await helper.getSource(state); const state = this.!currentTest.state; );

            – C. Peck
            Mar 10 at 10:13












          • I edited my answer because the comment was unreadable. Basically I'm trying to tell it 'yeah, this is undefined, so what'? To avoid the warning and move on.

            – C. Peck
            Mar 10 at 10:17











          • no, it didnt work. I got Multiple variable declarations in the same statement are forbiddents .

            – user6086008
            Mar 10 at 10:32












          • But i seem to have solved it by adding this: any in the function afterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)

            – user6086008
            Mar 10 at 10:35
















          0














          I think the error occurs because the access to this.currentTest.state happens inside another function: the arrow function passed in to afterEach--flow analysis does not cross function boundaries. Try simply pulling that line outside of the function:



          const helper = new HelperClass();
          afterEach(async ()=>
          const state = this.!currentTest.state;
          await helper.getSource(state);
          );


          Does that change anything?






          share|improve this answer

























          • if i put it outside of the function, i get: Property 'currentTest' does not exist on type 'Suite'. If i put it outside of the describe i get: 'this' implicitly has type 'any' because it does not have a type annotation'.

            – user6086008
            Mar 10 at 10:05











          • Um..... Try this: const helper = new HelperClass(); afterEach(async ()=> await helper.getSource(state); const state = this.!currentTest.state; );

            – C. Peck
            Mar 10 at 10:13












          • I edited my answer because the comment was unreadable. Basically I'm trying to tell it 'yeah, this is undefined, so what'? To avoid the warning and move on.

            – C. Peck
            Mar 10 at 10:17











          • no, it didnt work. I got Multiple variable declarations in the same statement are forbiddents .

            – user6086008
            Mar 10 at 10:32












          • But i seem to have solved it by adding this: any in the function afterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)

            – user6086008
            Mar 10 at 10:35














          0












          0








          0







          I think the error occurs because the access to this.currentTest.state happens inside another function: the arrow function passed in to afterEach--flow analysis does not cross function boundaries. Try simply pulling that line outside of the function:



          const helper = new HelperClass();
          afterEach(async ()=>
          const state = this.!currentTest.state;
          await helper.getSource(state);
          );


          Does that change anything?






          share|improve this answer















          I think the error occurs because the access to this.currentTest.state happens inside another function: the arrow function passed in to afterEach--flow analysis does not cross function boundaries. Try simply pulling that line outside of the function:



          const helper = new HelperClass();
          afterEach(async ()=>
          const state = this.!currentTest.state;
          await helper.getSource(state);
          );


          Does that change anything?







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 10 at 10:15

























          answered Mar 10 at 1:41









          C. PeckC. Peck

          876324




          876324












          • if i put it outside of the function, i get: Property 'currentTest' does not exist on type 'Suite'. If i put it outside of the describe i get: 'this' implicitly has type 'any' because it does not have a type annotation'.

            – user6086008
            Mar 10 at 10:05











          • Um..... Try this: const helper = new HelperClass(); afterEach(async ()=> await helper.getSource(state); const state = this.!currentTest.state; );

            – C. Peck
            Mar 10 at 10:13












          • I edited my answer because the comment was unreadable. Basically I'm trying to tell it 'yeah, this is undefined, so what'? To avoid the warning and move on.

            – C. Peck
            Mar 10 at 10:17











          • no, it didnt work. I got Multiple variable declarations in the same statement are forbiddents .

            – user6086008
            Mar 10 at 10:32












          • But i seem to have solved it by adding this: any in the function afterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)

            – user6086008
            Mar 10 at 10:35


















          • if i put it outside of the function, i get: Property 'currentTest' does not exist on type 'Suite'. If i put it outside of the describe i get: 'this' implicitly has type 'any' because it does not have a type annotation'.

            – user6086008
            Mar 10 at 10:05











          • Um..... Try this: const helper = new HelperClass(); afterEach(async ()=> await helper.getSource(state); const state = this.!currentTest.state; );

            – C. Peck
            Mar 10 at 10:13












          • I edited my answer because the comment was unreadable. Basically I'm trying to tell it 'yeah, this is undefined, so what'? To avoid the warning and move on.

            – C. Peck
            Mar 10 at 10:17











          • no, it didnt work. I got Multiple variable declarations in the same statement are forbiddents .

            – user6086008
            Mar 10 at 10:32












          • But i seem to have solved it by adding this: any in the function afterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)

            – user6086008
            Mar 10 at 10:35

















          if i put it outside of the function, i get: Property 'currentTest' does not exist on type 'Suite'. If i put it outside of the describe i get: 'this' implicitly has type 'any' because it does not have a type annotation'.

          – user6086008
          Mar 10 at 10:05





          if i put it outside of the function, i get: Property 'currentTest' does not exist on type 'Suite'. If i put it outside of the describe i get: 'this' implicitly has type 'any' because it does not have a type annotation'.

          – user6086008
          Mar 10 at 10:05













          Um..... Try this: const helper = new HelperClass(); afterEach(async ()=> await helper.getSource(state); const state = this.!currentTest.state; );

          – C. Peck
          Mar 10 at 10:13






          Um..... Try this: const helper = new HelperClass(); afterEach(async ()=> await helper.getSource(state); const state = this.!currentTest.state; );

          – C. Peck
          Mar 10 at 10:13














          I edited my answer because the comment was unreadable. Basically I'm trying to tell it 'yeah, this is undefined, so what'? To avoid the warning and move on.

          – C. Peck
          Mar 10 at 10:17





          I edited my answer because the comment was unreadable. Basically I'm trying to tell it 'yeah, this is undefined, so what'? To avoid the warning and move on.

          – C. Peck
          Mar 10 at 10:17













          no, it didnt work. I got Multiple variable declarations in the same statement are forbiddents .

          – user6086008
          Mar 10 at 10:32






          no, it didnt work. I got Multiple variable declarations in the same statement are forbiddents .

          – user6086008
          Mar 10 at 10:32














          But i seem to have solved it by adding this: any in the function afterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)

          – user6086008
          Mar 10 at 10:35






          But i seem to have solved it by adding this: any in the function afterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)

          – user6086008
          Mar 10 at 10:35




















          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%2f55069374%2fobject-is-probably-undefined-mocha%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

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко