reactjs - 有没有一种方法可以浅渲染使用 react-apollo 查询的反应组件
问题描述
这是我要测试的组件。我想为此使用浅渲染。
import React from 'react';
import { Query } from 'react-apollo';
import MY_QUERY from './MyQuery.graphql';
import Component from './Component';
const Container = () => (
<Query query={MY_QUERY}>
{({ loading, error, data }) => {
if (loading) return null;
if (error) return null;
return <Component data={data} />;
}}
</Query>
);
};
export default Container;
解决方案
shallow()
+renderProp()
将完成这项工作:
const wrapper = shallow(<Container />).find(Query);
const result = wrapper.renderProp('children')({ loading: false, data: someMockedData });
expect(result.find(Component).prop('data')).toEqual(someMockedData);
推荐阅读
- go - 如何持续分析我的 Go 应用程序?
- javascript - 使用模板文字动态创建 localStorage 键的问题
- python-3.x - 如何在 Python 3 的 pytube 模块中更改用户代理
- graphql - 如何使用 AppSync GraphQL 转换为双向一对多 @connection 执行字段级别 @auth?
- laravel - 如何使用 laravel 查询查找可用日期?
- javascript - 未处理的拒绝(TypeError):this.setState 不是函数
- swift - 如何使用 SwiftUI 获取 ScrollView 的动态文本高度
- java - Spring JPA 我可以将 pojo 传递给存储过程吗?
- apache-kafka - 如何将状态目录添加到嵌入式 Kafka 流?
- elasticsearch - 我在 kibana 网络客户端中找不到索引