How to add a synchronous helper function? #9426
Unanswered
marinakuranda
asked this question in
Questions and Help
Replies: 1 comment
-
What you are doing here (attaching a method to the global Cypress object) works, but I would advise to simply have common functions and require or export them just like plain JavaScript functions. // cypress/support/utils.js
export const parsePrice = (str) => parseFloat(/* some logic */)
// cypress/integration/specA.js
import {parsePrice} from '../support/utils'
// use parsePrice in your tests |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I want to use some shared logic across my tests.
But the way it is done is redundant to use commands.
Because commands are asynchronous and to rewrite a command to work in a synchronous seems redundant.
This is what I've added to my commands file:
It seems to work the expected way, but it is undocumented.
Do you recommend another approach for shared synchronous functions?
Beta Was this translation helpful? Give feedback.
All reactions