在Angular 13升级后,茉莉单元测试失败 - 预期的一个匹配请求“匹配方法:post,url:api/x/x search”,找到无

发布于 2025-01-27 01:50:52 字数 724 浏览 1 评论 0原文

从12个升级到Angular 13后,一些单元测试开始失败:

错误:预期的一个标准匹配请求“匹配方法:post,url:api/x/x-search”,没有发现。

这是模拟

async function mockXSearch(error?: string) {

const req = httpMock.expectOne({ method: 'POST', url: 'api/x/x-search' });
    if (error) {
      req.flush({ title: errorMsg }, { status: 500, statusText: 'Internal Server Error' });
    } else {
      req.flush(mockX, { status: 200, statusText: 'OK' });
    }
    return page.whenStable();
}

,这是服务:

searchX(someData: string, foo: number, xType: XType) {
    return this.http.post<X[]>(`${this.baseUrl}/x-search`, { someData, foo, xType });
}

我已经检查了模拟URL和服务URL使匹配。 有什么想法吗?

After upgrading to Angular 13 from 12, some of the Unit Tests started failing:

Error: Expected one matching request for criteria "Match method: POST, URL: api/x/x-search", found none.

This is the mock

async function mockXSearch(error?: string) {

const req = httpMock.expectOne({ method: 'POST', url: 'api/x/x-search' });
    if (error) {
      req.flush({ title: errorMsg }, { status: 500, statusText: 'Internal Server Error' });
    } else {
      req.flush(mockX, { status: 200, statusText: 'OK' });
    }
    return page.whenStable();
}

And this is the service:

searchX(someData: string, foo: number, xType: XType) {
    return this.http.post<X[]>(`${this.baseUrl}/x-search`, { someData, foo, xType });
}

I already checked that the Mock Url and the Service Url make match.
Any idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文