我正在尝试使用 Vue 测试库和 Apollo 设置组件测试,如他们的示例中所述。
import { ApolloClient, InMemoryCache } from '@apollo/client'
import { render } from '@testing-library/vue'
import VueApollo from 'vue-apollo'
const apolloClient = new ApolloClient({
uri: 'http://localhost:4001/graphql',
cache: new InMemoryCache({
addTypename: false,
}),
})
type ComponentType = Parameters<typeof render>[0]
const renderWithApollo = (Component: ComponentType) =>
render(Component, undefined, (localVue) => {
localVue.use(VueApollo)
return {
apolloProvider: new VueApollo({ defaultClient: apolloClient }),
}
})
但是,当我这样做时,TypeScriptdefaultClient
会出现以下错误:
Type 'ApolloClient<NormalizedCacheObject>' is missing the following properties from type 'ApolloClient<any>': store, writeData, initQueryManager, wsClientts(2739)
apollo-provider.d.ts(16, 5): The expected type comes from property 'defaultClient' which is declared here on type '{ defaultClient: ApolloClient<any>; defaultOptions?: VueApolloComponentOptions<Vue> | undefined; clients?: { [key: string]: ApolloClient<any>; } | undefined; watchLoading?: WatchLoading | undefined; errorHandler?: ErrorHandler | undefined; prefetch?: boolean | undefined; }'
ApolloClient 怎么会错过这些类型,我该如何赋予它这些属性?感觉好像我缺少配置。