我有一个GraphQLError
,如下所示:
export const notFoundError = (msg: string): GraphQLError => {
return new GraphQLError(msg, {
extensions: { code: "NOT_FOUND" }
});
};
字符串
假设一个函数抛出了这个错误
export function test() {
throw notFoundError("no item found")
}
型
我怎么测试这是玩笑?比如:
expect(() => {
test();
}).toThrow((error: GraphQLError) => {
// expect statements to test the message and code
})
型
我尝试了这个,然而,我得到一个错误说
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 | };
型
任何帮助都欢迎!
1条答案
按热度按时间jgovgodb1#
根据https://jestjs.io/docs/expect#tothrowerror上的文档
应该是这样的:
字符串
注意:看起来这只匹配消息