Last active
August 12, 2020 16:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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