我将 react-nativ 与 expo、jest-fetch-mock 和 graphql 一起使用。调用 api 时出现错误
× return user feed query (69ms)
● testing api › return user feed query
Unexpected end of JSON input
at new ApolloError (node_modules/@apollo/client/errors/index.js:29:28)
at node_modules/@apollo/client/core/QueryManager.js:611:19
at both (node_modules/@apollo/client/utilities/observables/asyncMap.js:16:53)
at node_modules/@apollo/client/utilities/observables/asyncMap.js:9:72
at tryCallTwo (node_modules/react-native/node_modules/promise/lib/core.js:45:5)
at doResolve (node_modules/react-native/node_modules/promise/lib/core.js:200:13)
api.test.js 从 'jest-fetch-mock' 导入获取;
import { getUserFeed } from '../feed'
describe('testing api', () => {
beforeEach(() => {
fetch.resetMocks()
})
it('return user feed query', async () => {
//assert on the response
await getUserFeed(20).then(async (res) => {
console.log('watcher ' + res)
});
//assert on the times called and arguments given to fetch
console.log('watch ' + fetch.mock.calls.length)
expect(fetch.mock.calls.length).toEqual(20)
})
})