Trouble/Weirdness with accessing aliased values in this context
#27293
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.
-
Hey everyone, I've been running into an issue with Cypress Component Testing that I can't seem to figure out.
What do I mean?
I'm trying to set up some aliases in a
beforeEachhook usingcy.wrap().as(), and then access these aliased values in my tests using thethiscontext. However, when I logthisin my tests, the aliased values areundefined.Here's a simplified version of my code where I'm facing this issue:
In this example, both
this.componentandthis.someObjectare logged asundefined, and trying to access a property onthis.componentthrows an error becausethis.componentisundefined.However, I have another example where the aliased values are logged as
undefined, but I can still access properties on them in my tests:In this second example,
this.componentandthis.someObjectare logged asundefined, just like in the first example. However, I can still accessthis.component.fooin my test, and it correctly logs'bar'.What I tried so far
I've tried a number of things to resolve this issue, but nothing seems to work. Here's a summary of what I've tried:
cy.then()after setting up the aliases: I thought that maybe the aliases weren't fully resolved when I was trying to access them, so I tried usingcy.then()after setting up the aliases. This allowed me to log the correct values inside thethenfunction, but the aliases were stillundefinedin the actual tests.Using a
beforehook instead of abeforeEachhook: I also tried using abeforehook instead of abeforeEachhook, thinking that there might be an issue with how thethiscontext was being handled between tests. However, this didn't change the behavior either - the aliases were stillundefinedin the tests.Using
cy.get('@alias').then()to access the aliased values: I tried usingcy.get('@alias').then()to access the aliased values, which did allow me to access the correct values in the tests. However, this approach is not ideal for us. It makes the tests less readable and more difficult to maintain. If we can't get thethiscontext working consistently across all test suites, we're considering using a Jasmine-like style where we use a variable scoped in thedescribeblock that is written and read, even though this is not idiomatic Cypress.Despite these attempts, I'm still facing the same issue - the aliases are
undefinedwhen I log them and when I try to access them in my tests, except in some cases where I can still access properties on the aliased values in my tests, even though they are logged asundefined.Beta Was this translation helpful? Give feedback.
All reactions