我正在测试PermissionDetail
具有 graphql 片段的组件,即 PermissionTable 组件的节点数据。从查询中获取模拟数据时,我在这一行中遇到流类型错误const permissionDetail = data.viewPermissionScheme?.grantGroups[0].grantHolders?.edges[0].node.permission;
。
组件层次结构:
App -> PermissionTable(分页组件片段) -> PermissionDetail(片段)
const TestRenderer = () => {
const data = useLazyLoadQuery<examplesPermissionQuery>(
graphql`
query examplesPermissionQuery @relay_test_operation {
viewPermission(id: "test-scheme-id") {
... on PermissionView {
groups {
holders(first: 10) {
edges {
node {
permission {
...permissionDetailsFragment
}
}
}
}
}
}
}
}
`,
{},
);
// Getting Flowtype Error here: Cannot get `data.viewPermission?.groups[0]` because an index signature declaring the expected key / value type is missing in null or undefined [1]
const permissionDetail =
data.viewPermissionScheme?.grantGroups[0].grantHolders?.edges[0].node.permission;
return permissionDetail ? (<PermissionDetails permissionDetail={permissionDetail}/>) : null;
};
测试此类组件的正确方法是什么?我是 flow 和 graphql 和中继的新手。所以需要了解测试这个的最佳方法。