0

我有这个查询,但 MSW 没有调用它。

const response = (await API.graphql(graphqlOperation(listNotarys, { filter: filterInput }))) as {
    data: unknown;
  };

我的处理程序如下所示:

  graphql.query("ListNotarys", (req, res, ctx) =>
    res(
      ctx.data({
        data: {
          listNotarys: {
            items: [
              {
                id: "123",
                email: "email@gmail.com",
                name: "Name Here",
                phone: null,
                group: "GROUP_A",
                lastSigningDate: null,
                createdAt: "2021-11-12T14:06:57.492Z",
                updatedAt: "2021-11-12T14:32:07.190Z",
              },
            ],
            nextToken: null,
          },
        },
      }),
    ),
  ),

我有一个如下所示的 setupTests.ts 文件:

beforeAll(() => {
  awsAmplify.Auth.signIn.mockRejectedValue("mock error");
  awsAmplify.Auth.currentAuthenticatedUser.mockResolvedValue("mock user");
  server.listen({ onUnhandledRequest: "error" });
});
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

在我的控制台中出现以下错误:

An unhandled error occured processing a request for the endpoint "listNotarys". 
      In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: Cannot read property 'error' of undefined] 
4

0 回答 0