Skip to content

Make fireEvent.update work with lazy modifier #183

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

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/__tests__/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<label for="movie-input">Title of the movie</label>
<input id="movie-input" v-model="title" name="title" />

<label for="director-input">Director of the movie</label>
<input id="director-input" v-model.lazy="director" name="director" />

<label id="review-textarea">Your review</label>
<textarea
v-model="review"
Expand All @@ -13,6 +16,14 @@
aria-labelledby="review-textarea"
/>

<label id="notes-textarea">Add some notes</label>
<textarea
v-model.lazy="notes"
name="notes-textarea"
placeholder="Add some notes"
aria-labelledby="notes-textarea"
/>

<label>
<input v-model="rating" type="radio" value="3" />
Wonderful
Expand Down Expand Up @@ -46,7 +57,9 @@ export default {
data() {
return {
title: '',
director: '',
review: '',
notes: '',
rating: '1',
recommend: false,
}
Expand All @@ -63,7 +76,9 @@ export default {

this.$emit('submit', {
title: this.title,
director: this.director,
review: this.review,
notes: this.notes,
rating: this.rating,
recommend: this.recommend,
})
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ test('Review form submits', async () => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
const fakeReview = {
title: 'An Awesome Movie',
director: 'Stephen Spielberg',
review: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
notes: 'Add something',
rating: '3',
}

Expand All @@ -31,9 +33,15 @@ test('Review form submits', async () => {
const titleInput = getByLabelText(/title of the movie/i)
await fireEvent.update(titleInput, fakeReview.title)

const directorInput = getByLabelText(/director of the movie/i)
await fireEvent.update(directorInput, fakeReview.director)

const reviewTextarea = getByPlaceholderText('Write an awesome review')
await fireEvent.update(reviewTextarea, fakeReview.review)

const notesTextarea = getByPlaceholderText('Add some notes')
await fireEvent.update(notesTextarea, fakeReview.notes)

// Rating Radio buttons.
const initiallySelectedInput = getByLabelText('Awful')
const ratingSelect = getByLabelText('Wonderful')
Expand Down
6 changes: 6 additions & 0 deletions src/vue-testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,18 @@ fireEvent.update = (elem, value) => {
return fireEvent.change(elem)
} else {
elem.value = value
if (elem._vModifiers && elem._vModifiers.lazy) {
return fireEvent.change(elem)
}
return fireEvent.input(elem)
}
}

case 'TEXTAREA': {
elem.value = value
if (elem._vModifiers && elem._vModifiers.lazy) {
return fireEvent.change(elem)
}
return fireEvent.input(elem)
}

Expand Down