apollo - 用于测试 graphql 错误的查询不再有模拟响应
问题描述
我遇到了问题:当我在模拟任何错误发生时使用 React 测试库时,查询没有更多的模拟响应。
我的查询是:
export const GET_AREA_COMPOSITION = gql`
query getAreaComposition($areaId: ID!) {
areaComposition(
areaId: $areaId
page: 1
first: 999999
) {
data {
id
areaCompositionRule
usePostalCodeRange
postalCodeFrom
postalCodeTo
postalCodeCountry
geoArea {
id
type
continent
country
state
city
}
}
}
}
`;
我的期望是有错误的模拟数据并像这样运行它:
const errorMocksData = [
{
request: {
query: GET_AREA_COMPOSITION,
variables: { areaId: 2073, page: 1, first: 9999, }
},
error: new Error("An error occurred")
}
];
it("Should display error on failure if graphql query data failed", async () => {
render(
render(
<MockedProvider>
<MyComponent {...props} />
</MockedProvider>
))
expect(await screen.findByText("No more mocked")).toBeVisible();
});
但是,我收到了这个错误:
No more mocked responses for the query: query getAreaComposition($areaId: ID!) {
areaComposition(areaId: $areaId, page: 1, first: 999999) {
data {
id
areaCompositionRule
usePostalCodeRange
postalCodeFrom
postalCodeTo
postalCodeCountry
geoArea {
id
type
continent
country
state
city
__typename
}
__typename
}
__typename
}
}
, variables: {"areaId":"2073"}
为什么我不再得到测试查询的模拟响应?如何修复错误?
解决方案
推荐阅读
- spring - 如何使用@scheduled 知道所有线程在spring boot @async 中完成
- android - 防止前台服务进入睡眠模式
- angular - 以角度绑定json数组值
- java - 在给定机器上控制 Java 线程创建的最佳方法是什么?
- android - 广播接收器未从 Google 短信检索器 API 接收短信
- php - 仅使用制作 API 所需的资源创建一个 Laravel 项目
- c++ - C++ 匿名结构作为 std::map 值
- sql - 从 SELECT 语句的结果集数据创建一个新的临时本地表
- php - 带有 tagDiv 报纸主题的受密码保护的 WordPress 网站被恶意软件感染
- apache - Apache .conf 文件“需要所有”实用程序?