0
子供を包むことになっているreact "ラッパー"成分があります。私は、レンダリングされた子がこのラッパーに提供されているものを実際にあるかどうかをテストするjest
を使用しようとしています反応成分の子供が実際に遊びの子であるかどうかのテスト
export class Wrapper extends Component {
render(){
return (<div>{ this.props.children }</div>);
}
}
:ここに関連する部分です。 ここに私が試みたものがあります。
describe('SwapWrapper',() => {
it('contains its child',() => {
const potentialChild = (<AMockedComponent/>);
const wrapper = TestUtils.renderIntoDocument(
<Wrapper>{potentialChild}</Wrapper>
);
const realChild = TestUtils.findRenderedComponentWithType(wrapper, AMockedComponent);
expect(realChild).toBe(potentialChild); // Obviously does not work.
});
});
明らかに機能しません。 realChild
is a component instance while potentialChild
is a component element。
現在、私ができることは、potentialChild
をプロパティで作成し、realChild
にこのプロパティが含まれていることを確認することだけです。
realChild
が提供されているpotentialChild
に実際に対応しているかどうかを確認する有効な方法はありますか?
これは同じインスタンスではないため動作しません。正しい型のコンポーネントであるかどうかをテストする場合は、 'type'プロパティ間の等価性をテストしてください:' expect(realChild.type).toBe(AMockedComponent) ' – Pcriulan
問題は私がチェックしたいだけです正しいタイプ。私はそれが提供されている要素に正確に*対応していることを確認したい。 –