简体   繁体   English

Jest 测试中 Express App 中的测试完成后无法登录问题

[英]Cannot log after tests are done problem in Express App in Jest tests

This is my Jest tests这是我的 Jest 测试

it('test the endpoint', async done => {
        const request = supertest('http://localhost:3000/myexp');
        request.get('/router1')
        .expect(200)
        .end((err, res) => {
            if(err) {
                throw err;
            } else {
                expect(res.text).toEqual('direct use 1st');
            }
        });
        done();
    })

The test runs successfully, but it said Cannot log after tests are done.测试运行成功,但它说测试完成后无法登录。 Since I sent the HTTP request to the Express App router and it was supposed to log some message like "API got request for [object Object]".由于我将 HTTP 请求发送到 Express App 路由器,并且它应该记录一些消息,例如“API 收到了 [object Object] 的请求”。

How can I log the message in this case?在这种情况下如何记录消息?

Try this and JSON.stringify(obj) to see your object试试这个和 JSON.stringify(obj) 来查看你的对象

 it('test the endpoint', async done => {
    const request = supertest('http://localhost:3000/myexp');
    request.get('/router1')
    .expect(200)
    .end((err, res) => {
        if(err) {
            throw err;
        } else {
            expect(res.text).toEqual('direct use 1st');
            done();
        }
    });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM