Passing a function as a parameter to a helper method
What are you trying to achieve?
Since functions which are not assigned to the I (actor) are not outputted as part of the printed steps, I was thinking of making a generic function in my helper and its param would be a function.
What do you get instead?
I am getting the error saying that the passed parameter is not a function.
Provide console output if related. Use
--verbosemode for more details.
# paste output here
Provide test source code if related
In my Scenario:
... let actualLimits = await depositPage.getDisplayedDepositLimits(); let expectedLimits = await depositPage.getLimitsFromOptionsService(payment.NAME); I.doAssertion(depositPage.verifyingDepositLimits(actualLimits,expectedLimits));
In my helper
... doAssertion(assertFunc){ assertFunc(); };
This way I would be able to keep my existing assertion methods within the page objects and start seeing these steps as part of the output.
Details
- CodeceptJS version: 1.1.4
- NodeJS Version: v.9.3.0
- Operating System: Mac OS High Sierra
- Protractor || WebDriverIO || Nightmare version (if related): WebdriverIO
You have a mistake in your code.
I.doAssertion(depositPage.verifyingDepositLimits(actualLimits,expectedLimits));
The problem is that you are not passing a function, instead you’re passing the result of your function.
Try
I.doAssertion(() => depositPage.verifyingDepositLimits(actualLimits,expectedLimits));
You're right :-) I realized afterwards that it evaluates and since the function does not have a return value, was returning as undefined. Thank you for the solution.
Don’t forget to close the issue once it’s resolved ;)
Thank you!