File tree 1 file changed +7
-12
lines changed
1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -4,29 +4,24 @@ import {render, fireEvent} from '@testing-library/vue'
4
4
import Component from './components/Fetch.vue'
5
5
6
6
test ( 'mocks an API call when load-greeting is clicked' , async ( ) => {
7
- axiosMock . get . mockImplementationOnce ( ( ) =>
8
- Promise . resolve ( {
9
- data : { greeting : 'hello there' } ,
10
- } ) ,
11
- )
7
+ axiosMock . get . mockResolvedValueOnce ( {
8
+ data : { greeting : 'hello there' } ,
9
+ } )
12
10
13
11
const { html, getByText} = render ( Component , { props : { url : '/greeting' } } )
14
12
15
13
await fireEvent . click ( getByText ( 'Fetch' ) )
16
14
17
15
expect ( axiosMock . get ) . toHaveBeenCalledTimes ( 1 )
18
16
expect ( axiosMock . get ) . toHaveBeenCalledWith ( '/greeting' )
17
+
19
18
getByText ( 'hello there' )
20
19
21
20
// You can render component snapshots by using html(). However, bear in mind
22
21
// that Snapshot Testing should not be treated as a replacement for regular
23
22
// tests.
24
23
// More about the topic: https://twitter.com/searls/status/919594505938112512
25
- expect ( html ( ) ) . toMatchInlineSnapshot ( `
26
- <div><button>
27
- Fetch
28
- </button> <span>
29
- hello there
30
- </span></div>
31
- ` )
24
+ expect ( html ( ) ) . toMatchInlineSnapshot (
25
+ `<div><button> Fetch </button><span>hello there</span></div>` ,
26
+ )
32
27
} )
You can’t perform that action at this time.
0 commit comments