reactjs - 无法将过滤后的对象反应到开玩笑的测试用例中
问题描述
我已经为下面创建了测试。
<ATMSelect
style={{ marginRight: 11 }}
options={options?.filter((i) => i.value !== '')}
onChange={(e, v) => setEmail(v?.value || '')}
/>
这是测试文件的代码,这里的问题是我希望选择节点被覆盖在伊斯坦布尔测试覆盖范围内,但由于此选项数据未填充到我的测试用例中而未被覆盖。
jest.mock('src/contexts/reset-password.context', () => ({
useResetPasswordContext: () => ({
status:{},
state: {
email: true,
options:[
{
key: "test",
value: "test@test.com",
text: "test",
},{
key: "test1",
value: "test1@test.com",
text: "test1",
}
],
status:[],
},
actions: jest.fn()
}),
}));
describe('ResetPassword View', () => {
it('Renders correctly', () => {
const wrapper = mount(<ResetPassword />);
expect(wrapper).toMatchSnapshot();
});
it('calls opensaveModal', () => {
const wrapper = mount(<ResetPassword />);
console.log(wrapper.find("ATMSelect").first().debug());
});
});
结果
console.log
<ATMSelect style={{...}} options={{...}} onChange={[Function: onChange]}>
<Select options={{...}} style={{...}} onChange={[Function: onChange]}>
<Dropdown options={{...}} style={{...}} onChange={[Function: onChange]} selection={true} additionLabel="Add " additionPosition="top" closeOnBlur={true} closeOnEscape={true} deburr={false} icon="dropdown" minCharacters={1} noResultsMessage="No results found." openOnFocus={true} renderLabel={[Function: renderItemContent]} searchInput="text" selectOnBlur={true} selectOnNavigation={true} wrapSelection={true}>
<Ref innerRef={{...}}>
<RefFindNode innerRef={{...}}>
<div style={{...}} role="listbox" aria-busy={[undefined]} aria-disabled={[undefined]} aria-expanded={false} aria-multiselectable={[undefined]} className="ui selection dropdown" onBlur={[Function (anonymous)]} onClick={[Function (anonymous)]} onKeyDown={[Function (anonymous)]} onMouseDown={[Function (anonymous)]} onFocus={[Function (anonymous)]} onChange={[Function (anonymous)]} tabIndex={0}>
<Icon name="dropdown" className="" onClick={[Function: onClick]} as="i">
<i onClick={[Function (anonymous)]} aria-hidden="true" className="dropdown icon" />
</Icon>
<DropdownMenu direction={[undefined]} open={[undefined]}>
<div className="menu transition" />
</DropdownMenu>
</div>
</RefFindNode>
</Ref>
</Dropdown>
</Select>
</ATMSelect>
测试应该返回带有选项的选择树,因为 html 在选项中使用过滤器,如果我删除该过滤器,那么它工作正常。
解决方案
推荐阅读
- xamarin - 从适用于 Android 和 IOS 的 Xamarin 表单中的 TextInputLayout 中删除占位符
- tfs - 无法使用 tf.exe 检出源代码
- java - Android libgdx:按下启动器图标后启动画面未立即显示
- java - 带有 Confluent 的 Spring Cloud Stream Kafka 不会产生与带有 Confluent 的 Spring Kafka 相同的消息
- python - 控制台不导出任何抓取的数据
- jodd - jre 7 支持哪个版本的 jodd-http?
- c# - 带有数据绑定的 LiveCharts 派生的用户控件不显示图表
- mysql - 使用外键从多表中删除数据
- angular - 从动态生成的表中过滤记录以进行角度更新
- firebase - 向 Firebase 规则添加管理员权限