diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-04 12:08:27 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-04 12:08:27 +0000 |
commit | 6724a6ee6b0898470e20f294f1328cc01891756a (patch) | |
tree | 64e5941568354ae4825f51788078362a4f189c64 /spec/frontend/helpers | |
parent | 477c2c26047bc2d2da32b31eb8b26a6397675931 (diff) | |
download | gitlab-ce-6724a6ee6b0898470e20f294f1328cc01891756a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/helpers')
-rw-r--r-- | spec/frontend/helpers/mock_apollo_helper.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/frontend/helpers/mock_apollo_helper.js b/spec/frontend/helpers/mock_apollo_helper.js new file mode 100644 index 00000000000..8a5a160231c --- /dev/null +++ b/spec/frontend/helpers/mock_apollo_helper.js @@ -0,0 +1,23 @@ +import { InMemoryCache } from 'apollo-cache-inmemory'; +import { createMockClient } from 'mock-apollo-client'; +import VueApollo from 'vue-apollo'; + +export default (handlers = []) => { + const fragmentMatcher = { match: () => true }; + const cache = new InMemoryCache({ + fragmentMatcher, + addTypename: false, + }); + + const mockClient = createMockClient({ cache }); + + if (Array.isArray(handlers)) { + handlers.forEach(([query, value]) => mockClient.setRequestHandler(query, value)); + } else { + throw new Error('You should pass an array of handlers to mock Apollo client'); + } + + const apolloProvider = new VueApollo({ defaultClient: mockClient }); + + return apolloProvider; +}; |