Enzyme如何获取依赖组件元素?
How to get dependency component element by Enzyme?
我正在基于我的 AutoComplete
组件创建一个 React
组件 (UserAutocomplete
)。
我的 AutoComplete
组件在哪里:
render(
<input type='text' class='autocomplete'/>
);
我的 UserAutoComplete
是:
import Autocomplete from './autocomplete';
render(
<Autocomplete {...this.props} />
);
并使用 Enzyme
+ Jest
创建测试,但是当我使用 find
函数获得 input
时,返回 null
.
it('test defaultValue prop', () => {
const wrapper = shallow(
<UserAutocomplete/>
);
console.log(wrapper.find('input')); // returning null
});
如果它在子组件中,我如何才能得到这个输入?
我正在基于我的 AutoComplete
组件创建一个 React
组件 (UserAutocomplete
)。
我的 AutoComplete
组件在哪里:
render(
<input type='text' class='autocomplete'/>
);
我的 UserAutoComplete
是:
import Autocomplete from './autocomplete';
render(
<Autocomplete {...this.props} />
);
并使用 Enzyme
+ Jest
创建测试,但是当我使用 find
函数获得 input
时,返回 null
.
it('test defaultValue prop', () => {
const wrapper = shallow(
<UserAutocomplete/>
);
console.log(wrapper.find('input')); // returning null
});
如果它在子组件中,我如何才能得到这个输入?