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
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
add a comment |
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
add a comment |
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
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
protractor mocha
asked Mar 8 at 18:57
user6086008user6086008
84210
84210
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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?
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 gotMultiple 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 functionafterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)
– user6086008
Mar 10 at 10:35
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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?
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 gotMultiple 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 functionafterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)
– user6086008
Mar 10 at 10:35
add a comment |
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?
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 gotMultiple 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 functionafterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)
– user6086008
Mar 10 at 10:35
add a comment |
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?
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?
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 gotMultiple 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 functionafterEach(function (this: any) { const state = this.currentTest.state; helper.getSource(state)
– user6086008
Mar 10 at 10:35
add a comment |
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 gotMultiple 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 functionafterEach(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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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