-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from testing-library/fix-radio-checkbox
Fix radio, checkbox and select
- Loading branch information
Showing
5 changed files
with
78 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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,25 @@ | ||
<template> | ||
<div> | ||
<label for="dino-select">Choose a dinosaur:</label> | ||
<select id="dino-select" v-model="selectedDino"> | ||
<option value="dino1">Tyrannosaurus</option> | ||
<option value="dino2">Velociraptor</option> | ||
<option value="dino3">Deinonychus</option> | ||
<optgroup label="Sauropods"> | ||
<option value="dino4">Diplodocus</option> | ||
<option value="dino5">Saltasaurus</option> | ||
<option value="dino6">Apatosaurus</option> | ||
</optgroup> | ||
</select> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
selectedDino: 'dino1' | ||
} | ||
} | ||
} | ||
</script> |
This file contains 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 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,27 @@ | ||
import { render, fireEvent } from '@testing-library/vue' | ||
import '@testing-library/jest-dom/extend-expect' | ||
import Select from './components/Select' | ||
|
||
// In this test file we showcase several ways to interact with a Select element | ||
test('Select component', async () => { | ||
let optionElement | ||
const { getByDisplayValue, getByText } = render(Select) | ||
|
||
// Get the Select element by using the initially displayed value | ||
const select = getByDisplayValue('Tyrannosaurus') | ||
expect(select.value).toBe('dino1') | ||
|
||
// Update it by manually sending a valid option value | ||
await fireEvent.update(select, 'dino2') | ||
expect(select.value).toBe('dino2') | ||
|
||
// We can trigger an update event by directly getting the <option> element | ||
optionElement = getByText('Deinonychus') | ||
await fireEvent.update(optionElement) | ||
expect(select.value).toBe('dino3') | ||
|
||
// ...even if option is within an <optgroup> | ||
optionElement = getByText('Diplodocus') | ||
await fireEvent.update(optionElement) | ||
expect(select.value).toBe('dino4') | ||
}) |