Skip to content

Commit

Permalink
Merge branch 'master' into input-file-test-fail
Browse files Browse the repository at this point in the history
  • Loading branch information
afontcu authored Nov 24, 2020
2 parents 06eced1 + 853d998 commit f408a45
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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 @@ -162,12 +162,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

0 comments on commit f408a45

Please sign in to comment.