vendredi 26 février 2021

How can I mock an ApolloError with code argument in @apollo/client fro testing?

I'm trying to test how my client handles a specific error I throw in my server like this:

throw new ApolloError("No applicant found", "APPLICANT_NOT_FOUND");

My client depends on the extensions.code part of result to handle the error. But since ApolloError from the package @apollo/client apparently doesn't work the same as the one in the server I cannot mock an error accordingly.

This is my mock so far:

export const getApplicantNotFound: Mock = {
  request: {
    query: GET_APPLICANT,
    variables: { codigo: "1234509876" },
  },
  result: {
//on this line typescript says: expected 1 argument but got 2
    errors: [new ApolloError(
      "No applicant found with code 123450987",
      "APPLICANT_NOT_FOUND"
    )],
  },
};

Do I need to install the apollo-server package to use the ApolloError that has extensions.code in my client tests? Or is there some way to mock this error in the client?

Aucun commentaire:

Enregistrer un commentaire