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

Bug: expose props can not access in test case. #2116

Closed
jason-chang opened this issue Jul 3, 2023 · 6 comments · Fixed by #2125
Closed

Bug: expose props can not access in test case. #2116

jason-chang opened this issue Jul 3, 2023 · 6 comments · Fixed by #2125
Labels
bug Something isn't working

Comments

@jason-chang
Copy link
Contributor

jason-chang commented Jul 3, 2023

Describe the bug
defineExpose can works fine in the browser, but does not work in the test case.
Got error like ⬇️
image

To Reproduce
To reproduce this problem I created a demo and put it in the CodeSandbox.

The link is here ⬇️

https://codesandbox.io/p/github/jason-chang/test-utils-bug/main

Components in src/components/Case.vue
For test cases, see src/components/tests/case.test.tsx
The browse test code is in src/App.vue

Expected behavior

You want defineExpose exported projects to be properly accessible in both browser and test case.

Related information:

Additional context

@jason-chang jason-chang added the bug Something isn't working label Jul 3, 2023
@cexbrayat
Copy link
Member

Hi @jason-chang

Thank you for the repro.
This is interesting and probably need to be fixed. We expose everything automatically on wrapper.vm, even without defineExpose, to make tests easier. But maybe we need some special handling for the aliases

If you're interested in contributing, there are tests in expose.spec.ts. You can try to add a test with an alias if there is none. The code to fix will be in vueWrapper.ts, around

function createVMProxy<T extends ComponentPublicInstance>(

@erikkkwu
Copy link

erikkkwu commented Jul 5, 2023

I'm not sure if implementing it this way in createVMProxy is a good approach, because it depends on the unref method
image

@jason-chang
Copy link
Contributor Author

jason-chang commented Jul 5, 2023

@cexbrayat Thank you for your reply.
I'm not sure I have what it takes, to solve this problem 😂, so maybe let me try tomorrow.
And I'm not sure if this is a @vue/test-utils issue or a @vue/compile-sfc issue? What do you think?

@cexbrayat
Copy link
Member

I'm pretty sure it's a test-utils problem. You can start by adding a unit test expose.spec.ts and see if it reproduces the problem. If it's too hard to fix no worries, someone from the team will take a look when we get some time 😉. Thanks!

@jason-chang
Copy link
Contributor Author

@cexbrayat ok👌

@jason-chang
Copy link
Contributor Author

@cexbrayat @erikkkwu Thanks your tips, I tried to create a pull request to fix & test this bug. #2125
Please review and decide whether to merge or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants