Giter VIP home page Giter VIP logo

Comments (9)

cexbrayat avatar cexbrayat commented on June 11, 2024 1

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.

cexbrayat avatar cexbrayat commented on June 11, 2024

Hi @nsakiya-incomm

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.

nsakiya-incomm avatar nsakiya-incomm commented on June 11, 2024

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.

cexbrayat avatar cexbrayat commented on June 11, 2024

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.

nsakiya-incomm avatar nsakiya-incomm commented on June 11, 2024

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.

cexbrayat avatar cexbrayat commented on June 11, 2024

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.

nsakiya-incomm avatar nsakiya-incomm commented on June 11, 2024

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.

cexbrayat avatar cexbrayat commented on June 11, 2024

@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.

renatodeleao avatar renatodeleao commented on June 11, 2024

@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.

https://stackblitz.com/edit/github-dbkkwg-vdtfvm?file=src%2Fcomponents%2F__tests__%2FHelloWorld.spec.ts

Cheers, hope you've made it!

from test-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.