-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
Improve onboarding by adding explanations
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`makes an API call and displays the greeting when load-greeting is clicked 1`] = ` | ||
<div><button> | ||
Fetch | ||
</button> <span> | ||
hello there | ||
</span></div> | ||
`; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import axiosMock from 'axios' | ||
import { render, fireEvent } from '@testing-library/vue' | ||
import Component from './components/Fetch.vue' | ||
import 'jest-dom/extend-expect' | ||
|
||
test('makes an API call and displays the greeting when load-greeting is clicked', async () => { | ||
axiosMock.get.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
data: { greeting: 'hello there' } | ||
}) | ||
) | ||
|
||
const { html, getByText } = render(Component, { props: { url: '/greeting' } }) | ||
|
||
// Act | ||
await fireEvent.click(getByText('Fetch')) | ||
|
||
expect(axiosMock.get).toHaveBeenCalledTimes(1) | ||
expect(axiosMock.get).toHaveBeenCalledWith('/greeting') | ||
getByText('hello there') | ||
|
||
// You can render component snapshots by using html(). However, bear in mind | ||
// that Snapshot Testing should not be treated as a replacement for regular | ||
// tests. | ||
// More about the topic: https://twitter.com/searls/status/919594505938112512 | ||
expect(html()).toMatchSnapshot() | ||
}) |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { render, waitForElementToBeRemoved } from '@testing-library/vue' | ||
import Disappearance from './components/Disappearance' | ||
import 'jest-dom/extend-expect' | ||
|
||
test('it waits for the data to be loaded', async () => { | ||
const { getByText, queryByText, queryByTestId } = render(Disappearance) | ||
|
||
// Assert initial state | ||
getByText('Loading...') | ||
expect(queryByText(/Loaded this message/)).not.toBeInTheDocument() | ||
|
||
// Line reads as follows "Wait until element with test 'Loading...' is gone." | ||
await waitForElementToBeRemoved(() => queryByText('Loading...')) | ||
// It is equivalent to: | ||
// | ||
// await wait(() => { | ||
// expect(queryByText('Loading...')).not.toBeInTheDocument() | ||
// }) | ||
// | ||
// `wait()` waits until the callback function passes or times out. | ||
|
||
// After 'Loading...' element is gone, we can assert that fetched data is | ||
// rendered. | ||
expect(queryByTestId('message')).toHaveTextContent(/Hello World/) | ||
|
||
// Read more about async utilities: | ||
// https://testing-library.com/docs/dom-testing-library/api-async | ||
}) |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.