Created
January 14, 2021 00:14
-
-
Save tvler/9c2bb54a42b49cb0c8e67f93149b5673 to your computer and use it in GitHub Desktop.
A mocked version of ApolloClient for Jest tests
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
import { ApolloCache, ApolloClient, ApolloLink, NormalizedCacheObject } from '@apollo/client'; | |
class MockedApolloLink extends ApolloLink { | |
split = jest.fn(); | |
concat = jest.fn(); | |
request = jest.fn(); | |
setOnError = jest.fn(); | |
protected onError = jest.fn(); | |
} | |
class MockedApolloCache extends ApolloCache<NormalizedCacheObject> { | |
read = jest.fn(); | |
write = jest.fn(); | |
diff = jest.fn(); | |
watch = jest.fn(); | |
reset = jest.fn(); | |
evict = jest.fn(); | |
restore = jest.fn(); | |
extract = jest.fn(); | |
removeOptimistic = jest.fn(); | |
performTransaction = jest.fn(); | |
transformDocument = jest.fn(); | |
gc = jest.fn(); | |
identify = jest.fn(); | |
readQuery = jest.fn(); | |
modify = jest.fn(); | |
readFragment = jest.fn(); | |
writeFragment = jest.fn(); | |
transformForLink = jest.fn(); | |
writeQuery = jest.fn(); | |
recordOptimisticTransaction = jest.fn(); | |
} | |
class MockedApolloClient extends ApolloClient<NormalizedCacheObject> { | |
link = new MockedApolloLink(); | |
cache = new MockedApolloCache(); | |
stop = jest.fn(); | |
query = jest.fn(); | |
readFragment = jest.fn(); | |
writeQuery = jest.fn(); | |
readQuery = jest.fn(); | |
writeFragment = jest.fn(); | |
restore = jest.fn(); | |
watchQuery = jest.fn(); | |
mutate = jest.fn(); | |
setLink = jest.fn(); | |
setLocalStateFragmentMatcher = jest.fn(); | |
setResolvers = jest.fn(); | |
subscribe = jest.fn(); | |
resetStore = jest.fn(); | |
clearStore = jest.fn(); | |
onClearStore = jest.fn(); | |
onResetStore = jest.fn(); | |
reFetchObservableQueries = jest.fn(); | |
extract = jest.fn(); | |
add = jest.fn(); | |
getResolvers = jest.fn(); | |
addResolvers = jest.fn(); | |
__actionHookForDevTools = jest.fn(); | |
__requestRaw = jest.fn(); | |
defaultOptions = {}; | |
disableNetworkFetches = false; | |
queryDeduplication = false; | |
typeDefs = undefined; | |
version = ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment