Reading a value from a function for a Cypress test run #28182
-
In a cypress test run I want to get a value in my fileWithTest.js from a function from the fileWithObjects.js. Besides having had different error messages before I made it that the test runs completely without error messages ... but with this remark: [object Undefined] The test part of this example code is: This is the part with the "function": fileWithObjects.js `functionForSpecificTableCell_Month2() {
}` This is the test file that uses the "outside function": fileWithTest.js `describe('Test Read From Outside Function', ()=> {
})` Result: The test runs without any error messages (all green) but this remark and value shows up in the input field: value in input field: [object Undefined] I can not return a value from the amount function. With my research I did not get any results fitting to my example. Maybe my apporach is completely wrong? I expected something like this: https://www.geeksforgeeks.org/javascript-return-statement/ Does not work for me. Any idea? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It appears that you are having trouble retrieving the result from the functionForSpecificTableCell_Month2 in your fileWithObjects.js. The issue arises from the asynchronous nature of Cypress instructions and the promise handling. You are returning a value from within an asynchronous.then() block in your fileWithObjects.js. When you return a value from within this block, the value from the functionForSpecificTableCell_Month2 function is not returned. Instead, it returns from the inner function supplied to.then() without passing the value to the outer function. To manage the asynchronous behavior, you may utilize Cypress promises appropriately. You may return a Cypress promise from your function and then handle the received value with.then() in your test file. Here's how to make changes to your fileWithObjects.js: |
Beta Was this translation helpful? Give feedback.
It appears that you are having trouble retrieving the result from the functionForSpecificTableCell_Month2 in your fileWithObjects.js. The issue arises from the asynchronous nature of Cypress instructions and the promise handling.
You are returning a value from within an asynchronous.then() block in your fileWithObjects.js. When you return a value from within this block, the value from the functionForSpecificTableCell_Month2 function is not returned. Instead, it returns from the inner function supplied to.then() without passing the value to the outer function.
To manage the asynchronous behavior, you may utilize Cypress promises appropriately. You may return a Cypress promise from your fun…