supertest测试,expect不同的状态码,但都能通过

问题

it("should return 401 if token has wrong tenant", async ()=>{ request(app).get('/abc').set("Authorization", token).expect(401) })
然而当我把expect 换成其他任何非401的数字,测试均能通过。

解决方法

去掉大括号
it("should return 401 if token has wrong tenant", async ()=> request(app).get('/abc').set("Authorization", token).expect(401) )

原文地址:https://www.cnblogs.com/mrlonely2018/p/15598526.html