简体   繁体   English

如何在 Jasmine 中对 httpParams 进行单元测试

[英]how to unit test httpParams in Jasmine

I'm pretty new in unit testing.我是单元测试的新手。 I have a function which is setting query params:我有一个 function 正在设置查询参数:

setParams(scale): HttpParams {
    return this.params = new HttpParams()
        .set('scale', scale);
}

The output is passing right to the http get method. output 将权利传递给 http 获取方法。 But I have no idea how to test if the function above is really giving http params.但我不知道如何测试上面的 function 是否真的给出了 http 参数。 Can anyone give me some advice?谁能给我一些建议? Thanks!谢谢!

Something along the lines of:类似于以下内容:

it('should set params', () => {
  const params = service.setParams('hello'); // I assume this is in the service code
  expect(params.get('scale')).toBe('hello');
});

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

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