在Node Express中设置玩笑和超级测试

时间:2019-10-28 01:45:35

标签: javascript node.js express jestjs supertest

我在我的node express上使用supertest和jest进行测试。我已经设法用此代码测试帖子

it('should create a new quote', async (done) => {
    const res = await request(app).post('/api/quotes')
    .attach('image', 'tests/test_files/test-file.jpg')
    .field('from', 'Test')
    .field('quote', 'Test')
    .field('image_name', 'test-file.jpg')

    expect(res.statusCode).toEqual(200);
    expect(res.body).toHaveProperty('result', true);
    expect(res.body).toHaveProperty('msg', 'Successfully inserted a quote');
    done();
});

测试用例通过了,但是当它保存在数据库中时,请求协议和标头主机已更改

由于在手动测试中使用enter image description here,因此在我使用玩笑和超级测试进行测试时已更改为enter image description here

有什么主意我应该如何将玩笑的URL设置为http://localhost:5000而不是使用127.0.0.1

我对节点Express的测试是新手,我不知道要搜索什么或如何设置。

0 个答案:

没有答案
相关问题