Where are these variables ("aliases") coming from? #25260
Unanswered
marco-globality
asked this question in
Questions and Help
Replies: 0 comments
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there!
So my team is using aliases to set some important variables which are used within the it('Test',) blocks.
So for example, we may be running the following command in a before step:
cy.setupSomeDynamicData()
Then the
setupSomeDynamicData()
method exists in a another file (ex: commands.js) and thesetupSomeDynamicData()
method may setup a couple aliases:cypress/support/commands.js
So now we go back to our spec/test file, and start using these aliases:
cypress/e2e/smallTest.cy.js
The problem is that unless you're the person who wrote the code, it's not obvious where
this.String1
,this.String2
, orthis.String3
are coming from nor when they were initialized (from the perspective ofsmallTest.cy.js
) since the code that initializes the aliases is being executed in another file.In this example, it's quite easy to Ctrl+F the codebase and search for these aliases but you have to really start doing some reverse engineering once you have more complex use cases.
I guess this feels like some sort of readability/maintainability problem because once you setup enough of these and the example I provided starts to get more complex then finding out where these aliases are created can be inconvenient. The this.* syntax makes it feel like you'd find these aliases variables somewhere within the same file in which they're being used but when you don't see any sign of them then it becomes evident that they've just magically been initialized (somewhere/somehow) and then the hunt 🕵🏼♂️ begins.
Some solutions that come to mind (which may be bad ideas) are:
Anyhow, I'm sure there may be a better way to handle this so just thought I'd post this question.
Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions