首页 > 解决方案 > 无法将过滤后的对象反应到开玩笑的测试用例中

问题描述

我已经为下面创建了测试。

<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 在选项中使用过滤器,如果我删除该过滤器,那么它工作正常。

标签: reactjsjestjsenzyme

解决方案


推荐阅读