You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is that while the model is passed as a prop, the onUpdate:modelValue event isn't configured, causing unexpected behavior with Vue's reactivity system.
Expected solution
I'd like the mount comand to allow me to do this easily:
Clicking the mutateButton works as expected, but once the replaceButton is clicked, the component becomes buggy — it updates the model, but the DOM doesn't reflect the changes.
it('doesnt work when mounting the component with a model props',()=>{constmodel={count: 0};cy.mount(DoubleCounter,{props: {modelValue: model,},});cy.dataCy('mutateButton').click();cy.dataCy('count').should('have.text','1');cy.dataCy('replaceButton').click();cy.dataCy('count').should('have.text','2');cy.dataCy('mutateButton').click();cy.dataCy('count').should('have.text','3');// <----- FAILS 😢});
Current solution
As per vue-test-utils documention, I can manually set the onUpdate:modelValue. Unfortunately, cy.mount doesn't provide direct access to the VueWrapper, so I had to find a workaround.
This is what I came up with:
it('does work when mounting the component with a model props and an update prop',()=>{// eslint-disable-next-line @typescript-eslint/no-explicit-anyletcomponentWrapper: any;constmodel={count: 0};cy.mount(DoubleCounter,{props: {modelValue: model,'onUpdate:modelValue': (updatedModel: {count: number})=>{componentWrapper?.setProps({modelValue: updatedModel});},},}).then((component)=>{componentWrapper=component.wrapper;});cy.dataCy('mutateButton').click();cy.dataCy('count').should('have.text','1');cy.dataCy('replaceButton').click();cy.dataCy('count').should('have.text','2');cy.dataCy('mutateButton').click();cy.dataCy('count').should('have.text','3');// <---- WORKS 🥳});
This is tedious and could be impemented in the mount command directly.
Thank you :)
The text was updated successfully, but these errors were encountered:
This is a feature request
Problem when mounting components with a
v-model
When using
cy.mount
in my component tests, I have difficulty correctly mounting the component with av-model
binding.My old way of doing it was like this:
The issue is that while the model is passed as a prop, the
onUpdate:modelValue
event isn't configured, causing unexpected behavior with Vue's reactivity system.Expected solution
I'd like the mount comand to allow me to do this easily:
Example:
Take this simple
DoubleCounter.vue
componentClicking the
mutateButton
works as expected, but once thereplaceButton
is clicked, the component becomes buggy — it updates the model, but the DOM doesn't reflect the changes.Current solution
As per
vue-test-utils
documention, I can manually set theonUpdate:modelValue
. Unfortunately,cy.mount
doesn't provide direct access to theVueWrapper
, so I had to find a workaround.This is what I came up with:
This is tedious and could be impemented in the
mount
command directly.Thank you :)
The text was updated successfully, but these errors were encountered: