-
Notifications
You must be signed in to change notification settings - Fork 111
Warn when users are using fireEvent.input or .change directly #166
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ee571c6
Add warning message to fireEvent input and change when called directl…
jhack32 6403105
Add user event test case
jhack32 1313450
Reword warning message to include used event key
jhack32 2134a46
Fix template literal for warning messages
jhack32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,73 @@ | ||
<template> | ||
<div> | ||
<h1>Movie Review</h1> | ||
<form @submit.prevent="submit"> | ||
<label for="movie-input">Title of the movie</label> | ||
<input id="movie-input" v-model="title" name="title" /> | ||
<label id="review-textarea">Your review</label> | ||
<textarea | ||
v-model="review" | ||
name="review-textarea" | ||
placeholder="Write an awesome review" | ||
aria-labelledby="review-textarea" | ||
/> | ||
<label> | ||
<input v-model="rating" type="radio" value="3" /> | ||
Wonderful | ||
</label> | ||
<label> | ||
<input v-model="rating" type="radio" value="2" /> | ||
Average | ||
</label> | ||
<label> | ||
<input v-model="rating" type="radio" value="1" /> | ||
Awful | ||
</label> | ||
<label id="recommend-label">Would you recommend this movie?</label> | ||
<input | ||
id="recommend" | ||
v-model="recommend" | ||
type="checkbox" | ||
name="recommend" | ||
/> | ||
<button :disabled="submitDisabled" type="submit"> | ||
Submit | ||
</button> | ||
</form> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
data() { | ||
return { | ||
title: '', | ||
review: '', | ||
rating: '1', | ||
recommend: false, | ||
} | ||
}, | ||
computed: { | ||
submitDisabled() { | ||
return !this.title || !this.review | ||
}, | ||
}, | ||
methods: { | ||
submit() { | ||
if (this.submitDisabled) return | ||
this.$emit('submit', { | ||
title: this.title, | ||
review: this.review, | ||
rating: this.rating, | ||
recommend: this.recommend, | ||
}) | ||
}, | ||
}, | ||
} | ||
</script> | ||
<template> | ||
<div> | ||
<h1>Movie Review</h1> | ||
<form @submit.prevent="submit"> | ||
<label for="movie-input">Title of the movie</label> | ||
<input id="movie-input" v-model="title" name="title" /> | ||
|
||
<label id="review-textarea">Your review</label> | ||
<textarea | ||
v-model="review" | ||
name="review-textarea" | ||
placeholder="Write an awesome review" | ||
aria-labelledby="review-textarea" | ||
/> | ||
|
||
<label> | ||
<input v-model="rating" type="radio" value="3" /> | ||
Wonderful | ||
</label> | ||
<label> | ||
<input v-model="rating" type="radio" value="2" /> | ||
Average | ||
</label> | ||
<label> | ||
<input v-model="rating" type="radio" value="1" /> | ||
Awful | ||
</label> | ||
|
||
<label id="recommend-label" for="recommend"> | ||
Would you recommend this movie? | ||
</label> | ||
<input | ||
id="recommend" | ||
v-model="recommend" | ||
type="checkbox" | ||
name="recommend" | ||
/> | ||
|
||
<button :disabled="submitDisabled" type="submit">Submit</button> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
title: '', | ||
review: '', | ||
rating: '1', | ||
recommend: false, | ||
} | ||
}, | ||
computed: { | ||
submitDisabled() { | ||
return !this.title || !this.review | ||
}, | ||
}, | ||
|
||
methods: { | ||
submit() { | ||
if (this.submitDisabled) return | ||
|
||
this.$emit('submit', { | ||
title: this.title, | ||
review: this.review, | ||
rating: this.rating, | ||
recommend: this.recommend, | ||
}) | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import '@testing-library/jest-dom' | ||
import {render} from '@testing-library/vue' | ||
import userEvent from '@testing-library/user-event' | ||
import Form from './components/Form' | ||
import Select from './components/Select' | ||
|
||
beforeEach(() => { | ||
jest.spyOn(console, 'warn').mockImplementation(() => {}) | ||
}) | ||
|
||
afterEach(() => { | ||
console.warn.mockRestore() | ||
}) | ||
|
||
test('User events in a form', async () => { | ||
const fakeReview = { | ||
title: 'An Awesome Movie', | ||
review: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
rating: '3', | ||
} | ||
const {getByText, getByLabelText, emitted} = render(Form) | ||
|
||
const submitButton = getByText('Submit') | ||
expect(submitButton).toBeDisabled() | ||
|
||
const titleInput = getByLabelText(/title of the movie/i) | ||
await userEvent.type(titleInput, fakeReview.title) | ||
expect(titleInput.value).toEqual(fakeReview.title) | ||
|
||
const textArea = getByLabelText(/Your review/i) | ||
await userEvent.type(textArea, 'The t-rex went insane!') | ||
expect(textArea.value).toEqual('The t-rex went insane!') | ||
|
||
await userEvent.clear(textArea) | ||
expect(textArea.value).toEqual('') | ||
await userEvent.type(textArea, fakeReview.review) | ||
expect(textArea.value).toEqual(fakeReview.review) | ||
|
||
const initialSelectedRating = getByLabelText(/Awful/i) | ||
const wonderfulRadioInput = getByLabelText(/Wonderful/i) | ||
expect(initialSelectedRating).toBeChecked() | ||
expect(wonderfulRadioInput).not.toBeChecked() | ||
|
||
await userEvent.click(wonderfulRadioInput) | ||
expect(wonderfulRadioInput).toBeChecked() | ||
expect(initialSelectedRating).not.toBeChecked() | ||
|
||
const recommendInput = getByLabelText(/Would you recommend this movie?/i) | ||
await userEvent.click(recommendInput) | ||
expect(recommendInput).toBeChecked() | ||
|
||
userEvent.tab() | ||
expect(submitButton).toHaveFocus() | ||
expect(submitButton).toBeEnabled() | ||
await userEvent.type(submitButton, '{enter}') | ||
expect(emitted().submit[0][0]).toMatchObject(fakeReview) | ||
|
||
expect(console.warn).not.toHaveBeenCalled() | ||
}) | ||
|
||
test('selecting option with user events', async () => { | ||
const {getByDisplayValue} = render(Select) | ||
const select = getByDisplayValue('Tyrannosaurus') | ||
expect(select.value).toBe('dino1') | ||
|
||
await userEvent.selectOptions(select, 'dino2') | ||
expect(select.value).toBe('dino2') | ||
|
||
await userEvent.selectOptions(select, 'dino3') | ||
expect(select.value).not.toBe('dino2') | ||
expect(select.value).toBe('dino3') | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should actually be
so that it renders "change" or "input" 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that!