Node.js使用Jest捕获异步错误

Node.js使用Jest捕获异步错误,node.js,jestjs,Node.js,Jestjs,我觉得我在这里太过火了,需要一个理智的检查,我在和SuperTest开玩笑 Q1)如果expectexpect(res.status).toBe(400)失败会导致阻塞火灾吗 问题2)我应该抛出错误还是抛出新错误() 问题3)Jess是否只处理这个问题,而我不需要try-catch语句 const testUrl = '/register'; const headers = ['Accept', 'application/json']; it('should validate that the

我觉得我在这里太过火了,需要一个理智的检查,我在和SuperTest开玩笑

Q1)如果expect
expect(res.status).toBe(400)失败会导致阻塞火灾吗

问题2)我应该
抛出错误
还是
抛出新错误()

问题3)Jess是否只处理这个问题,而我不需要try-catch语句

const testUrl = '/register';
const headers = ['Accept', 'application/json'];

it('should validate that the `email` has already been registered and throw 400 error', async (done) => {
    try {
        const res = await request(app).post(testUrl).set(headers).send({
            email: 'test@myDomain.com',
            fullName: 'test user',
            password: 'testPassword!',
        });
        expect(res.status).toBe(400);
        expect(res.body.message).toEqual('You have already registered');
    } catch (error) {
        error.message = `${error.message}\n\nfailing query: ${testUrl}`;
        throw error;
    } finally {
        done();
    }
});

为什么不使用supertest的助手方法?不,你不需要你贴的大部分内容。@jornsharpe你有没有可以给我举个例子?-多个例子展示了他们的expect方法,整个过程就是一个承诺。