I am facing an issue with a GraphQLError
:
export const notFoundError = (msg: string): GraphQLError => {
return new GraphQLError(msg, {
extensions: { code: "NOT_FOUND" }
});
};
Additionally, there is a function that throws this error
export function test() {
throw notFoundError("no item found")
}
I am wondering how to properly test this in jest. Is this the correct approach?
expect(() => {
test();
}).toThrow((error: GraphQLError) => {
// Expect statements here to verify message and code
})
Upon attempting this, I encountered the following error:
expect(received).toThrow(expected)
Expected constructor name is an empty string
Received constructor: GraphQLError
Received message: "no item found"
2 |
3 | export const notFoundError = (msg: string): GraphQLError => {
> 4 | return new GraphQLError(msg, {
| ^
5 | extensions: { code: "NOT_FOUND" }
6 | });
7 | };
If anyone has any advice on how to resolve this, please share!