object is probably 'undefined' - Mocha The Next CEO of Stack OverflowHow 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 this transistor (2n2222) take 6V on emitter-base? Am I reading datasheet incorrectly?

How can I separate the number from the unit in argument?

Planeswalker Ability and Death Timing

Calculating discount not working

Why can't we say "I have been having a dog"?

Upgrading From a 9 Speed Sora Derailleur?

Is this a new Fibonacci Identity?

Is it correct to say moon starry nights?

Can Sri Krishna be called 'a person'?

Can you teleport closer to a creature you are Frightened of?

Gauss' Posthumous Publications?

Why doesn't Shulchan Aruch include the laws of destroying fruit trees?

Is the offspring between a demon and a celestial possible? If so what is it called and is it in a book somewhere?

Could a dragon use its wings to swim?

Does Germany produce more waste than the US?

Prodigo = pro + ago?

Why does freezing point matter when picking cooler ice packs?

Another proof that dividing by 0 does not exist -- is it right?

pgfplots: How to draw a tangent graph below two others?

Find a path from s to t using as few red nodes as possible

Calculate the Mean mean of two numbers

What did the word "leisure" mean in late 18th Century usage?

Early programmable calculators with RS-232

Which acid/base does a strong base/acid react when added to a buffer solution?



object is probably 'undefined' - Mocha



The Next CEO of Stack OverflowHow 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










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

          862324




          862324












          • 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

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme