で構成Reactjs成分Iは、組成物を通じて、特殊なコンポーネントを作成するように反応するドキュメントのアドバイスに従っ:テスト酵素
import React from 'react';
import AlertPanel from './AlertPanel';
export default class SpecialAlertPanel extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<AlertPanel text="special" />
) ;
}
}
AlertPanel
が通過テストを持っている
export default class AlertPanel extends React.Component {
constructor(props) {
super(props);
}
render() {
textRows = <div>{this.props.text}</div>;
}
return (
<Alert bsStyle={this.props.style} onDismiss={this.props.onDismiss}>
{textRows}
</Alert>
);
}
...と... :
it('should render AlertPanel to a div', function() {
const wrapper = shallow(<AlertPanel />);
expect(wrapper.type()).to.eql('div');
});
私は同等のテストがSpecialAlertPanel
:
it('should render SpecialAlertPanel to a div', function() {
const wrapper = shallow(<SpecialAlertPanel />);
expect(wrapper.type()).to.eql('div');
});
しかし、このテストは失敗します。
expected [Function: AlertPanel] to deeply equal 'div'
は私のテストや故障で私のコードですか? https://github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/type.mdから
は御馳走を作品のおかげで(もちろん、あなたが将来的には、余分な機能を追加した場合
SpecialAlertPanel
にテストを追加する必要があります)。 – slim