You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/src/guide/testing.md
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,27 @@ test('called Apollo mutation in addHero() method', () => {
41
41
})
42
42
```
43
43
44
+
### Testing loading state with mocking $apollo
45
+
If you want to test how your component renders when results from the GraphQL API are still loading, you can also mock a loading state in respective Apollo queries:
46
+
47
+
```js
48
+
test('renders correctly when loading allHeroes', () => {
49
+
constwrapper=mount(App, {
50
+
mocks: {
51
+
$apollo: {
52
+
queries: {
53
+
allHeroes: {
54
+
loading:true,
55
+
},
56
+
},
57
+
},
58
+
},
59
+
})
60
+
61
+
expect(wrapper.element).toMatchSnapshot();
62
+
})
63
+
```
64
+
44
65
## Tests with mocked GraqhQL schema
45
66
46
67
You can also make some more deep and complicated tests with [mocked GraphQL schema](https://www.apollographql.com/docs/graphql-tools/mocking.html). This method doesn't include Apollo, but lets you check if certain query will be executed correctly with given schema.
0 commit comments