小编raj*_*ddy的帖子

有没有办法在 MockedProvider - Apollo Client 中模拟重新获取?

这是我使用 MockedProvider 的方式。如何在模拟数组中模拟重新获取?

const mocks = [{
        request: {
            query: GET_USERS_BY_FACILITY,
            variables: {
                facility: 300
            }
        },
        result: {
            data: {
                GetUsersByFacility: [{
                    nuId: 'Q916983',
                    userName: faker.internet.userName(),
                    profileKey: 'testKey',
                    profileValue: 'testValue',
                    __typename: 'FacilityUser'
                }]
            }
        },
        refetch: () => {
            return {
                data: {
                    GetUsersByFacility: [{
                        nuId: 'Q916983',
                        userName: faker.internet.userName(),
                        profileKey: 'testKey',
                        profileValue: 'testValue',
                        __typename: 'FacilityUser'
                    }]
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

该测试用例在触发删除事件时调用 refetch 函数。

 it('should be able to click on delete user', async () => {
        const {getByTestId} = render( …
Run Code Online (Sandbox Code Playgroud)

reactjs graphql apollo-client react-testing-library

5
推荐指数
1
解决办法
8468
查看次数