Skip to content

Commit 343ccdf

Browse files
committed
Rename fetch -> axios-mock
1 parent 63b6f3f commit 343ccdf

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`makes an API call and displays the greeting when load-greeting is clicked 1`] = `
4+
<div><button>
5+
Fetch
6+
</button> <span>
7+
hello there
8+
</span></div>
9+
`;

tests/__tests__/__snapshots__/fetch.js.snap

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

tests/__tests__/axios-mock.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import axiosMock from 'axios'
2+
import { render, fireEvent } from '@testing-library/vue'
3+
import Component from './components/Fetch.vue'
4+
import 'jest-dom/extend-expect'
5+
6+
test('makes an API call and displays the greeting when load-greeting is clicked', async () => {
7+
axiosMock.get.mockImplementationOnce(() =>
8+
Promise.resolve({
9+
data: { greeting: 'hello there' }
10+
})
11+
)
12+
13+
const { html, getByText } = render(Component, { props: { url: '/greeting' } })
14+
15+
// Act
16+
await fireEvent.click(getByText('Fetch'))
17+
18+
expect(axiosMock.get).toHaveBeenCalledTimes(1)
19+
expect(axiosMock.get).toHaveBeenCalledWith('/greeting')
20+
getByText('hello there')
21+
22+
// You can render component snapshots by using html(). However, bear in mind
23+
// that Snapshot Testing should not be treated as a replacement for regular
24+
// tests.
25+
// More about the topic: https://twitter.com/searls/status/919594505938112512
26+
expect(html()).toMatchSnapshot()
27+
})

tests/__tests__/fetch.js

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

0 commit comments

Comments
 (0)