Open FelixNumworks opened 1 month ago
Here is my overwritten mount
command:
Cypress.Commands.overwrite('mount', (originalFn, component, mountOptions) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let componentWrapper: any;
if (mountOptions?.props && component.emits) {
for (const emit of component.emits as string[]) {
if (!emit.startsWith('update:')) continue;
const modelName = emit.replace('update:', '');
if (!mountOptions.props[modelName]) continue;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mountOptions.props[`onUpdate:${modelName}`] = (updatedModel: any) => {
componentWrapper?.setProps({ [modelName]: updatedModel });
};
}
}
return originalFn(component, mountOptions).then(({ wrapper, component }) => {
componentWrapper = wrapper;
return { wrapper, component };
});
});
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 :)