【问题标题】:How do I e2e test axios我如何 e2e 测试 axios
【发布时间】:2019-12-11 12:04:44
【问题描述】:

我是 node.js 的新手

我在我的 node.js 应用程序中有一个使用 axios 的基本请求逻辑。

axios.get('https://www.github.com');

我想验证响应信息(状态、正文、标头)。

如何验证?

【问题讨论】:

    标签: javascript node.js axios


    【解决方案1】:

    您可以使用jest

    以下代码验证响应状态代码。

    it('Test request check github status code.', async done => {
      const response = await axios.get('https://www.github.com');
      expect(response.status).toBe(200);
      done();
    });
    

    运行测试代码,您将看到以下成功消息。

    Test Suites: 1 passed, 1 total
    Tests:       1 passed, 1 total
    Snapshots:   0 total
    Time:        3.374s
    Ran all test suites.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 2017-04-02
      • 1970-01-01
      相关资源
      最近更新 更多