在@hapi/lab 单元测试中提供查询参数时出现问题

问题描述 投票:0回答:1

我正在尝试使用

@hapi/lab
@hapi/code
来实施测试。 我正在了解如何提供查询参数以进行测试,因为没有选项可以在
Options
中传递它。 在我的 API 中,我有 2 个参数要传递,1)JWT 令牌,即
authorization
和 2)查询
{ "name": "string" }
请指导我如何输入查询参数,然后根据它进行检查。这是我创建的测试用例。

describe('Routes', () => {
  let server;
  let response;

  describe('with JWT token /dashboard', () => {
    beforeEach(async () => {
      server = await init();
    });

    it('it returns a 200', async () => {
      const authorization = await authenticate(server);
      const Options = {
        method: 'GET',
        url: '/dashboard',
        headers: {
          authorization,
        },
      };
      response = await server.inject(Options);
      expect(response.statusCode).to.equal(200);
    });
  });
unit-testing hapi.js
1个回答
0
投票

server.inject({url:'/xyz?id='+term})

并声明

常量项 = 'abc';

在它的块内并通过查询参数检查

© www.soinside.com 2019 - 2024. All rights reserved.