Skip to content

Commit 5d2a434

Browse files
committed
Rename end-to-end -> disappearance
1 parent 343ccdf commit 5d2a434

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

tests/__tests__/components/EndToEnd.vue renamed to tests/__tests__/components/Disappearance.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<template>
2-
<div>
3-
<div v-if="loading">Loading...</div>
4-
<div v-else data-testid="message">
5-
Loaded this message: {{ data.returnedMessage }}
6-
</div>
7-
</div>
2+
<p v-if="loading">Loading...</p>
3+
<p v-else data-testid="message">
4+
Loaded this message: {{ data.returnedMessage }}
5+
</p>
86
</template>
97

108
<script>
@@ -13,6 +11,7 @@ const fetchAMessage = () =>
1311
// we are using random timeout here to fireEvent a real-time example
1412
// of an async operation calling a callback at a non-deterministic time
1513
const randomTimeout = Math.floor(Math.random() * 100)
14+
1615
setTimeout(() => {
1716
resolve({ returnedMessage: 'Hello World' })
1817
}, randomTimeout)

tests/__tests__/disappearance.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { render, waitForElementToBeRemoved } from '@testing-library/vue'
2+
import Disappearance from './components/Disappearance'
3+
import 'jest-dom/extend-expect'
4+
5+
test('it waits for the data to be loaded', async () => {
6+
const { getByText, queryByText, queryByTestId } = render(Disappearance)
7+
8+
// Assert initial state
9+
getByText('Loading...')
10+
expect(queryByText(/Loaded this message/)).not.toBeInTheDocument()
11+
12+
// Line reads as follows "Wait until element with test 'Loading...' is gone."
13+
await waitForElementToBeRemoved(() => queryByText('Loading...'))
14+
// It is equivalent to:
15+
//
16+
// await wait(() => {
17+
// expect(queryByText('Loading...')).not.toBeInTheDocument()
18+
// })
19+
//
20+
// `wait()` waits until the callback function passes or times out.
21+
22+
// After 'Loading...' element is gone, we can assert that fetched data is
23+
// rendered.
24+
expect(queryByTestId('message')).toHaveTextContent(/Hello World/)
25+
26+
// Read more about async utilities:
27+
// https://testing-library.com/docs/dom-testing-library/api-async
28+
})

tests/__tests__/end-to-end.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)