Comments (9)
Oh that's interesting, thanks for the trick @renatodeleao ! 👍
I'll close the issue then, as I think that the two possible workarounds are good enough.
If someone wants to dig into setData and open a PR, they are more than welcome to of course!
from test-utils.
Can you provide us a small repro online (as minimal as possible to reproduce the issue, ideally without vuteify, the store and axios) using https://stackblitz.com/github/vuejs/create-vue-templates/tree/main/typescript-vitest?file=src%2Fcomponents%2F__tests__%2FHelloWorld.spec.ts ?
It only takes a few minutes, and we'll be able to take a look
from test-utils.
Thanks, @cexbrayat .
Here is the sample codes, based on your template. I'm new to stackblitz.
https://stackblitz.com/edit/github-dbkkwg?file=src%2Fcomponents%2F__tests__%2FHelloWorld.spec.ts
from test-utils.
Thanks for the repro.
setData
is probably not as well supported as it was in VTU v1, as nowadays most people use the composition API (and then can't use setData
in their tests).
So in your case, if you prefer using the Options API, I would not use setData
in the test, but use await wrapper.get('input').setValue("Overridden!!!")
which solves the issue (and is closer to what your user would do).
Would that be an acceptable workaround for you?
from test-utils.
Hi @cexbrayat ,
I chose to use text field input to simplify the sample. The actual application is using v-autocomplete component from Vuetify, which is a little more complicated than that. I cannot directly invoke setValue()
. There might be the way, but not without going into their implementation level, which probably make the tests fragile to Vuetify implementation. We cannot go back to VTU1 because of Vue3 migration. Do you have other alternatives?
Unfortunately, we had lot of codes in Option API from Vue 2, as well as tests using setData()
. We're afraid that moving to Composition API would limit us from testing as thorough as what we have today.
Thank you.
from test-utils.
I understand. In my opinion, you'll have an easier time testing if you use the composition API (as you can see setData
is a bit rough).
If you want to take a look and try to open a PR to fix this issue, it would be great. We would gladly review and merge it!
from test-utils.
HI @cexbrayat ,
I'm new to this PR process. So, I open a PR and fix the issue by myself? I haven't thought about that. Can you guide me where to find setData() implementation in the source codes. I can give it a shot w/o knowing what I'm getting into. :)
Thanks
from test-utils.
@nsakiya-incomm You can start by adding a minimal unit test to reproduce the issue here https://github.com/vuejs/test-utils/blob/main/tests/setData.spec.ts
then setData
is defined in https://github.com/vuejs/test-utils/blob/main/src/vueWrapper.ts#L242, and you'll need to check what's going on 👍 Thanks for your help!
from test-utils.
@nsakiya-incomm Way late to the party, but also had my share of setData
when doing a big migration so I was compeled to leave this comment.
What was suggested is the way to go, you should test the way users interact with your components. So whenever you see a wrapper.vm
around your spider sense should warn you: these are implementation details. The name of data/computed properties are implementation details that can be changed without changing the output — and thus breaking the test.
Now back to the subject:
cannot directly invoke setValue(). There might be the way, but not without going into their implementation level,
.setValue
has a second argument prop
that allows use to basically v-model
on components. So on your case all you need to do is:
const inputComponent = wrapper.findComponent({ name: 'HelloWorldChild' });
await inputComponent.setValue('Overridden!!!', 'modelValue'); // the trick
Since it's a vuetify
wrapper, you can even stub it to hide its internal details, but not strictly necessary. Here's a demo with the test passing.
Cheers, hope you've made it!
from test-utils.
Related Issues (20)
- Feature request: mount should accept a partial that describes local properties on component HOT 1
- Bug: Circular references in props cause "Maximum call stack size exceeded" since v2.4.5 HOT 7
- Bug: findComponent doesn't find anything when using @vue/compat HOT 4
- DOMWrapper giving different return than createWrapper. HOT 6
- .setValue to work on `[contenteditable=true]` elements HOT 3
- Bug: "to" is missing from the attribute in RouterLinkStub HOT 1
- Bug: isDeepRef causes "RangeError: Maximum call stack size exceeded" HOT 1
- Bug: Scoped slots always undefined when shallow mounting and `renderStubDefaultSlot` is enabled HOT 1
- Docs: afterEach in teleport section causes issues on happy-dom HOT 1
- dev: use eslint v9
- Bug: Event declared via $attrs in mount not establishing prop prefixed with `on` HOT 3
- Using useSlots will report a warning HOT 1
- Bug: Stubs broken in `[email protected]` HOT 4
- Bug: Maximum call stack size exceeded, only happen on version 2.4.5 HOT 1
- Bug: Transition - [Vue warn]: Wrong type passed as event handler to xxx - did you forget @ or : in front of your prop? HOT 6
- Bug: Need to preserve code of keydown event
- Bug: TypeScript errors with Vue generic components HOT 3
- Bug: stubbing not working in a Vue+TSX project HOT 3
- Bug: `renderToString` always generates an empty html comment HOT 4
- chrome will remove `DOMXXX` event listeners on July 30 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from test-utils.