我正在开发 Angular 应用程序,并使用 Jasmine 来测试该应用程序。
我想要的是用一种方法测试两个相似的HTTP 请求,例如ngOnInit().
我有一个 HTTP 请求,在方法中调用了两次ngOnInit(),现在编写我使用的测试用例,抛出如下错误:
错误:预期条件“匹配 URL:http://localhost:8080/api/demoList ”有 1 个匹配请求,但发现 2 个请求。
例如,
// method to test
ngOnInit() {
this.httpGetRequest();
// some other code
this.httpGetRequest();
}
this.httpGetRequest() {
this.httpClient.get(http://localhost:8080/api/getSomeList);
}
//test case for ngOnInit()
it('should do something', () => {
spyOn(component, 'ngOnInit').and.callThrough();
component.ngOnInit();
const req = httpTestingController.expectOne(`http://localhost:8080/api/getSomeList`);
expect(req.request.method).toEqual('GET');
req.flush(mockList);
});
Run Code Online (Sandbox Code Playgroud)
如何测试类似 URL 的多个请求?
我在Spring Boot应用程序中使用mapstruct将Dto映射到实体,反之亦然。
我想知道,有没有一种方法可以使用 mapstruct @Mapping() 将任何 String 值作为空值映射到null值 ?
是否可以?
提前致谢