Skip to content

Commit

Permalink
docs: added instructions about mocking loading state (#883)
Browse files Browse the repository at this point in the history
* docs: add loading state mock instruction

* fix: fixed linting issues
  • Loading branch information
NataliaTepluhina authored and Akryum committed Dec 11, 2019
1 parent 0cacb94 commit b8ad10b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/docs/src/guide/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ test('called Apollo mutation in addHero() method', () => {
})
```

### Testing loading state with mocking $apollo
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:

```js
test('renders correctly when loading allHeroes', () => {
const wrapper = mount(App, {
mocks: {
$apollo: {
queries: {
allHeroes: {
loading: true,
},
},
},
},
})

expect(wrapper.element).toMatchSnapshot();
})
```

## Tests with mocked GraqhQL schema

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.
Expand Down

0 comments on commit b8ad10b

Please sign in to comment.