Ich habe DetailPanel
Komponente, die Detail
enthält mit title
Prop.React + Jest Check Komponente enthält eine andere Komponente
import React from 'react';
import Detail from './Detail';
import InfoTable from './InfoTable';
import EdgeIcon from './EdgeIcon';
import styles from './DetailsPanel.css';
export default class DetailsPanel extends React.PureComponent {
renderTitle() {
const { selectedEdge } = this.props;
if (selectedEdge) {
const sourceNode = 'sourceNode'
const targetNode = 'targetNode'
return (
<span>
{sourceNode}
<EdgeIcon className={styles.arrowIcon} />
{targetNode}
</span>
);
}
return 'default title';
}
render() {
return (
<Detail title={this.renderTitle()} />
);
}
}
ich binden, das überprüfen, ob selectedEdge
ist true
Details Titel EdgeIcon
Komponente
test('Detail should contain EdgeIcon if there is selected edge',() => {
const selectedEdge = { source: 1, target: 2 };
const detailsPanel = shallow(
<DetailsPanel
{...props}
selectedEdge={selectedEdge}
/>);
expect(detailsPanel.contains('EdgeIcon')).toBeTruthy();
});
Aber Test nicht enthält, weil detailsPanel false