-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update @testing-library/dom (#125)
BREAKING CHANGE: The latest version of DOM Testing Library has several breaking changes, so you will want to review its changelog to ensure you are unaffected. Also, this release drops support for Node 8. Upgrade to Node 10 or greater.
- Loading branch information
Showing
8 changed files
with
555 additions
and
791 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
module.exports = { | ||
printWidth: 80, | ||
tabWidth: 2, | ||
useTabs: false, | ||
semi: false, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
bracketSpacing: false, | ||
jsxBracketSameLine: false, | ||
proseWrap: 'always', | ||
} | ||
module.exports = require('kcd-scripts/prettier') |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,44 +1,53 @@ | ||
import '@testing-library/jest-dom' | ||
import {render, wait, fireEvent} from '@testing-library/vue' | ||
import StopWatch from './components/StopWatch.vue' | ||
|
||
test('updates component state', async () => { | ||
const {getByTestId, getByText} = render(StopWatch) | ||
|
||
const startButton = getByText('Start') | ||
const elapsedTime = getByTestId('elapsed') | ||
|
||
// Assert initial state. | ||
expect(elapsedTime).toHaveTextContent('0ms') | ||
getByText('Start') | ||
|
||
await fireEvent.click(startButton) | ||
|
||
getByText('Stop') | ||
|
||
// Wait for one tick of the event loop. | ||
await wait() | ||
|
||
// Stop the timer. | ||
await fireEvent.click(startButton) | ||
|
||
// We can't assert a specific amount of time. Instead, we assert that the | ||
// content has changed. | ||
expect(elapsedTime).not.toHaveTextContent('0ms') | ||
}) | ||
|
||
test('unmounts a component', async () => { | ||
jest.spyOn(console, 'error').mockImplementation(() => {}) | ||
|
||
const {unmount, isUnmounted, getByText} = render(StopWatch) | ||
await fireEvent.click(getByText('Start')) | ||
|
||
// Destroys a Vue component instance. | ||
unmount() | ||
|
||
expect(isUnmounted()).toBe(true) | ||
|
||
await wait() | ||
|
||
expect(console.error).not.toHaveBeenCalled() | ||
}) | ||
import '@testing-library/jest-dom' | ||
import {render, waitFor, fireEvent} from '@testing-library/vue' | ||
import StopWatch from './components/StopWatch.vue' | ||
|
||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
test('updates component state', async () => { | ||
const {getByTestId, getByText} = render(StopWatch) | ||
|
||
const startButton = getByText('Start') | ||
const elapsedTime = getByTestId('elapsed') | ||
|
||
// Assert initial state. | ||
expect(elapsedTime).toHaveTextContent('0ms') | ||
getByText('Start') | ||
|
||
await fireEvent.click(startButton) | ||
|
||
getByText('Stop') | ||
|
||
// Wait for one tick of the event loop. | ||
await waitFor(() => { | ||
expect(elapsedTime).not.toHaveTextContent('0ms') | ||
}) | ||
const timeBeforeStop = elapsedTime.textContent | ||
|
||
// Stop the timer. | ||
await fireEvent.click(startButton) | ||
|
||
// Wait for a few milliseconds | ||
await sleep(5) | ||
|
||
// We can't assert a specific amount of time. Instead, we assert that the | ||
// content has changed. | ||
expect(elapsedTime).toHaveTextContent(timeBeforeStop) | ||
}) | ||
|
||
test('unmounts a component', async () => { | ||
jest.spyOn(console, 'error').mockImplementation(() => {}) | ||
|
||
const {unmount, isUnmounted, getByText} = render(StopWatch) | ||
await fireEvent.click(getByText('Start')) | ||
|
||
// Destroys a Vue component instance. | ||
unmount() | ||
|
||
expect(isUnmounted()).toBe(true) | ||
|
||
// Wait for a few milliseconds | ||
await sleep(5) | ||
|
||
expect(console.error).not.toHaveBeenCalled() | ||
}) |
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