Material-UIオートコンプリートを薄くラップするコンポーネントのテストに問題があります。私のテストでは、渡されている小道具を見たいのですが、私のコンソールステートメントは空のオブジェクトです。私はこれを表現するために酵素の浅い方法を使用しています。ここに私のコードは次のとおりです。Enzyme Shallowを使用して子コンポーネントに渡された小道具をテストするにはどうすればよいですか?
const underlineFocusStyle = {
display: 'block',
height: '100%',
outline: 'none',
position: 'relative',
padding: '0px',
width: '100%',
border: 'none',
backgroundColor: 'rgba(0, 0, 0, 0)',
cursor: 'inherit',
opacity: '1'
};
export class MyAutoComplete extends React.Component {
render() {
let { muiTheme, forceOpenOnFocus, ...propsToApply } = this.props;
propsToApply.underlineFocusStyle = underlineFocusStyle;
if (forceOpenOnFocus) {
if (!propsToApply.filter) {
propsToApply.filter = ((searchText, key) => {
return searchText === '' || AutoComplete.defaultProps.filter(searchText, key);
});
}
}
return <AutoComplete name={'autocomplete'} {...propsToApply} />;
}
}
MyAutoComplete .propTypes = {
muiTheme: PropTypes.object,
forceOpenOnFocus: PropTypes.bool
}
export default muiThemeable()(MyAutoComplete);
そして、私のテスト:
describe('LLamasoftAutoComplete',() => {
const muiTheme = getMuiTheme();
const shallowWithContext = (node) => shallow(node, {context: {muiTheme}});
it('should pass in ',() => {
const wrapper = shallowWithContext(
<LLamasoftAutoComplete
muiTheme={muiTheme}
forceOpenOnFocus={true}
dataSource={['One', 'Two', 'Three']} />
);
console.log(wrapper.find('AutoComplete').props()); // is {}
expect(true).toBe(false);
});
});
Ahhhhhhh、私は私が適用されていたHOCを忘れてしまいました。私は今日これを撃つでしょう。 – TheTFo