-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathstopwatch.js
33 lines (23 loc) · 917 Bytes
/
stopwatch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import StopWatch from './components/StopWatch.vue'
import { cleanup, render, wait, fireEvent } from '@testing-library/vue'
import 'jest-dom/extend-expect'
afterEach(cleanup)
test('unmounts a component', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {})
const { unmount, isUnmounted, getByText } = render(StopWatch)
await fireEvent.click(getByText('Start'))
unmount()
expect(isUnmounted()).toBe(true)
await wait()
expect(console.error).not.toHaveBeenCalled()
})
test('updates component state', async () => {
const { getByTestId, getByText } = render(StopWatch)
const startButton = getByText('Start')
const elapsedTime = getByTestId('elapsed')
expect(elapsedTime).toHaveTextContent('0ms')
await fireEvent.click(startButton)
await wait()
await fireEvent.click(startButton)
expect(elapsedTime).not.toHaveTextContent('0ms')
})