Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Last active August 12, 2020 16:22
Show Gist options
  • Save Luke-Rogerson/9f9ef0e734907fcd3d29f93bbce0ae9a to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/9f9ef0e734907fcd3d29f93bbce0ae9a to your computer and use it in GitHub Desktop.
This is a VSCode gist to generate an Apollo cache update resolver test for easy TDDing
"TypeScript Apollo Resolver Test": {
"prefix": "tart",
"body": [
"import { FetchResult } from 'apollo-link'",
"import { DataProxy } from 'apollo-cache'",
"import { createMockResolverArgs } from '@rg-dev/apollo/src/test-utils/resolvers.utils'",
"",
"afterEach(() => jest.clearAllMocks())",
"",
"test('it should ', () => {",
"\tconst queryInCache = {}",
"",
"\tconst mutationPayload: FetchResult<> = {",
"\t\tdata: {},",
"\t}",
"",
"\tconst writeQuery: DataProxy.WriteQueryOptions<{}, {}> = {}",
"",
"\tconst readQueryMock = jest.fn(() => null)",
"\tconst writeQueryMock = jest.fn()",
"",
"\tconst mockResolverArgs = createMockResolverArgs({ readQueryMock, writeQueryMock, mutationPayload })",
"",
"\t// yourResolver(mockResolverArgs)",
"\texpect(readQueryMock).toHaveBeenCalledTimes(1)",
"\texpect(writeQueryMock).toHaveBeenCalledTimes(1)",
"\texpect(writeQueryMock).toHaveBeenCalledWith(writeQuery)",
"})",
"",
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment