Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Cypress component testing, exposed values in a script setup component are not accessible on the component instance (AKA wrapper.vm) #26575

Closed
segevfiner opened this issue Apr 24, 2023 · 5 comments · Fixed by #26633
Assignees
Labels
CT Issue related to component testing

Comments

@segevfiner
Copy link

segevfiner commented Apr 24, 2023

Current behavior

In Cypress component testing, exposed values in a script setup component are not accessible on the component instance (AKA wrapper.vm).

This is available when using @vue/test-utils directly in vitest.

image

Desired behavior

Exposed values from a script setup component are accessible.

P.S. The type returned inside Chainable by mount is not easily accessible as it is defined inline, which makes it hard to use via an alias (as/get). It might be nice to turn it into an exported interface for ease of use?

Test code to reproduce

https://github.com/segevfiner/cypress-test-utils-expose-issue

Cypress Version

12.10.0

Node version

v16.20.0

Operating System

macOS 13.3.1

Debug Logs

cypress-debug.log

Other

The same kind of test works in vitest.

@warrensplayer
Copy link
Contributor

@segevfiner This appears to be due to the older version of @vue/test-utils that is used in the Cypress vue mount adaptor.

@lmiller1990 Can you confirm my hypothesis? The @vue/test-utils dependency has not been updated in 7 months or so. Is that easy to update without causing a breaking change?

@warrensplayer warrensplayer added the CT Issue related to component testing label Apr 28, 2023
@lmiller1990
Copy link
Contributor

lmiller1990 commented May 1, 2023

Sure, we should be able to bump to https://github.com/vuejs/test-utils/releases/tag/v2.3.2 without breaking.

v2.4.0 has vuejs/test-utils#2026 which may permanent fix this need to constantly update types, but it might be a breaking change, so I'm not sure if we can adopt it yet.

Edit... I tried dropping in Test Utils v2.3.2, I'm getting a bunch of typing errors that are very difficult to understand. I am wondering if we should just make mount take any as the type, since this is proving quite disruptive to users, at least until we've got a more maintainable solution.

@lmiller1990
Copy link
Contributor

lmiller1990 commented May 1, 2023

Actually, I got the types to work. I see the value but I cannot access it:

image

I think this is related to how we use a Proxy in cypress/vue, to wrap anothter proxy in Test Utils... eg here.

Oddly enough, Reflect.has(component, 'hello') is true, but Reflect.get(component, 'hello') is undefined.

@lmiller1990
Copy link
Contributor

Fixed in #26633

defineExpose({
  hello: 'world'
})

Will never work. See docs. defineExpose is only for variables declared - like const, let etc. I think this will solve your issue, though, of accessed bindings that are in defineExpose.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 9, 2023

Released in 12.12.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.12.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CT Issue related to component testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants