如何在Jest Enzyme中编写禁用属性的单元测试用例?

时间:2020-10-14 16:07:02

标签: reactjs typescript unit-testing jestjs enzyme

我正在尝试为Material UI FormControl组件上的禁用属性编写单元测试用例。我已经写了测试用例,但是失败了。我的组件代码是-

<FormControl className={classes.formControl} disabled={assignFilerData.dispatch === 'MethodOfInspection' ? false : true}>
                                    <NativeSelect
                                        value={assignFilerData.dispatchType}
                                        onChange={handleDispatchChange}
                                        inputProps={{
                                            name: 'name',
                                            id: 'name-native-disabled',
                                        }}
                                    >
                                        <option value="">None</option>
                                        <option value="A">A</option>
                                        <option value="B">B</option>
                                        <option value="C">C</option>
                                        <option value="D">D</option>
                                    </NativeSelect>                                            
                                    </FormControl>

我对上述组件的单元测试用例是-

it('should render FromControl component', () => {
    const render = shallow(<Assignment />);
    const grid = render.find(FormControl).props('disabled').toBe(true);
    render.unmount();
});

我在Assignment Component内部包装了FormControl。我使用disable属性进行了单元测试,但是失败了。有人可以调查一下吗?

0 个答案:

没有答案