reactjs - 带有 JSX 道具的组件在 ezyme 浅包装上失败
问题描述
我正在尝试从采用JSX propSelect
的 material-UI 中测试组件。input
我收到以下错误Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s
。
删除input
线通过了测试,但这不是目的。
一般信息:
- 我在反应 16 上使用酶
- 这是尝试使用浅 eznyme 方法和酶到 json 的组件的浅快照
- 这仅在测试时失败,实施方式基于此示例https://codesandbox.io/s/qicub?file=/demo.js第 70 行
零件:
const SelectControl = ({
classes,
customClass,
options,
controlValue,
setControlValue,
}: Props) => (
<FormControl className={customClass}>
<Select
value={controlValue}
onChange={(event) => setControlValue(event.target.value)}
input={<SelectInput />}
>
{!!placeHolder && (
<MenuItem value="" disabled className={classes.dropdownItem}>
<Typography variant="subtitle1">{placeHolder}</Typography>
</MenuItem>
)}
{options.map(({ value, description }) => (
<MenuItem value={value} key={value} className={classes.dropdownItem}>
<Typography variant="subtitle1">{description}</Typography>
</MenuItem>
))}
</Select>
</FormControl>
);
测试:
test('renders correctly WITHOUT the optional props', () => {
// WHEN
const tree = shallowSnapshot(<SelectControl {...commonProps} />);
// THEN
expect(tree).toMatchSnapshot();
});
浅快照实现:
const shallowSnapshot = (Component) =>
toJson(shallow(Component), {
mode: 'shallow',
});
解决方案
推荐阅读
- python - 如何在 PyQt5 和 python 网络浏览器中添加新的选项卡功能
- php - 在php中用cmd ping ip
- r - R如何从输出中获取一行文本
- php - 未处理的异常 [0]:调用未定义的函数 get_sql_for_list_inquiry()
- javascript - 如何检查通过rest参数传递的对象是否为空或未定义?
- ruby-on-rails - 我无法验证邮递员参数中收到的电子邮件
- ios - SpriteKit applyImpulse 不影响精灵
- javascript - 如果满足密码条件,则删除跨度
- azure - 为容器的 Web 应用程序中的每个容器分配了多少内存和 CPU?
- ruby-on-rails - 如何从序列化对象中跳过关系哈希