i am using tdd and i not sure if i should test contrary cases or only expected case.
test 1
test('should render loading placeholder if isloading = true', () => {
const wrapper = shallow(
<OrderDetails id="10" />
);
wrapper.setState({ isLoading: true });
expect(wrapper.find(LoadingPlaceholder).length).toBe(1);
})
test 2
test('should not render loading placeholder if isloading = false', () => {
const wrapper = shallow(
<OrderDetails id="10" />
);
wrapper.setState({ isLoading: false});
expect(wrapper.find(LoadingPlaceholder).length).toBe(0);
})
component
export default class OrderDetails extends PureComponent {
state = {
isLoading: true,
}
props: Props;
render() {
return (
<div>
{this.state.isLoading && (
<LoadingPlaceholder />
)}
</div>
)
}
}
notes if only add the first test can pass the test with this for example unexpecected pass test
export default class OrderDetails extends PureComponent {
state = {
isLoading: true,
}
props: Props;
render() {
return (
<div>
<LoadingPlaceholder />
</div>
)
}
}
Aucun commentaire:
Enregistrer un commentaire