ich die Rat der React Dokumentation folgte eine spezielle Komponente, die durch Komposition zu erstellen:Testen eine komponierten Reactjs Komponente mit Enzyme
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>
);
}
... und ...
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
haben einen vorübergehenden Test :
it('should render AlertPanel to a div', function() {
const wrapper = shallow(<AlertPanel />);
expect(wrapper.type()).to.eql('div');
});
Ich dachte, ein äquivalenter Test würde fürfunktionieren 10:
it('should render SpecialAlertPanel to a div', function() {
const wrapper = shallow(<SpecialAlertPanel />);
expect(wrapper.type()).to.eql('div');
});
Aber dieser Test fehlschlägt:
expected [Function: AlertPanel] to deeply equal 'div'
Ist mein Test oder bei Störung meinen Code?
Arbeitet einen Genuss, danke. – slim