-
Notifications
You must be signed in to change notification settings - Fork 110
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
Warn about v-model components not handled with fireEvent.change #83
Comments
Do we have docs about it? I'm currently struggling with updating a custom component in a form using |
is |
If that's the case, would you mind opening up a new issue with a reproduction link? All Thanks!! 🙌 |
If I understand the code for fireEvent, this function just fires native events, right? if I want to update a component, I should update it as the user does, for example in my selector, I would click open, and choose the right value. right? |
|
I actually found a very nice solution, I'll try to post an example |
I've got an issue that i think is related to this one. I've got a custom input file component that use v-file-input from vuetify. My component emit Here is my code : <template>
<v-file-input
accept=".xlsx"
label="Matrice certifié nego"
name="matrix"
prepend-icon="mdi-file-table"
:rules="[required]"
@change="change"
></v-file-input>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
name: 'MatriceInputFile',
props: {
value: File
},
methods: {
required(value: File): boolean | string {
return (
value !== undefined ||
'Vous devez fournir une matrice de négociation tarrifaire.'
);
},
change(value: File) {
this.$emit('input', value);
}
}
});
</script> export const renderWithVuetify = <V extends Vue>(
component: VueClass<V>,
options?: RenderOptions<V>,
callback?: ConfigurationCallback<V>
) => {
return render(
// anonymous component
Vue.extend({
// Vue's render function
render(createElement) {
// add data-app="true" attribut and render the test component
return createElement(component, { attrs: { 'data-app': true } });
}
}),
// for Vuetify components that use the $vuetify instance property
{ vuetify: new Vuetify(), ...options },
callback
);
};
async function selectFile(inputFile: HTMLInputElement): Promise<void> {
const file = new File(['(⌐□_□)'], 'chucknorris.png', {
type: 'image/png'
});
await fireEvent.focus(inputFile);
await fireEvent.change(inputFile, { target: { files: [file] } });
await fireEvent.blur(inputFile);
}
it('should get selected file to parent component', async () => {
const { getByLabelText, emitted } = renderWithVuetify(MatriceInputFile);
const inputFile = getByLabelText(
'Matrice certifié nego'
) as HTMLInputElement;
await selectFile(inputFile);
expect(emitted()['input']).toBeDefined();
}); |
I noticed this while testing a component too. |
@afontcu - Is this something that needs to be done? I can give it a try |
Hi @jhack32! Yeah sure! 🚀 I think it'd be great to add a warning message when using typing events on elements that we know may cause unexpected issues, and suggest people to use |
Should it trigger a warning for the input file? |
since issue occurred with input file too, it seems logic to me to trigger warning on input file too ? |
Then we wouldn't be able to do this |
Hi! I'm not entirely sure what's the suggestion with input file – can't you simulate a file uploading using |
Since this was released in #166, I'll go ahead and close this issue, feel free to open up a new one if we're missing some warnings! thank you all! |
I am trying to use this for vuetify text field and nothing seems to work. |
More often than not people relies on
fireEvent.input
orfireEvent.change
to handle v-model powered inputs, thus running into issues with input value not being properly updated.I'm wondering if we should provide some kind of warning when that happens.
Does it make sense?
The text was updated successfully, but these errors were encountered: