Skip to content

Commit b8ad10b

Browse files
NataliaTepluhinaAkryum
authored andcommitted
docs: added instructions about mocking loading state (#883)
* docs: add loading state mock instruction * fix: fixed linting issues
1 parent 0cacb94 commit b8ad10b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/docs/src/guide/testing.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ test('called Apollo mutation in addHero() method', () => {
4141
})
4242
```
4343

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+
const wrapper = 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+
4465
## Tests with mocked GraqhQL schema
4566

4667
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

Comments
 (0)