Open HookyQR opened 3 years ago
React does not differentiate between a prop that’s present and undefined, vs a prop that’s absent. In other words, if the prop is present and undefined, then the props object does not in fact “have” the prop, per react semantics.
.to.have.props(['first', 'second', 'third']) //
passes.
Chai Enzyme should be able to be used to determine if the property (key) is passes, no matter what the value, without having to check ALL props passed.
is .to.have.props([])
meant to have "any" or "all" semantics?
I didn't change props
. It currently has all
semantics and matches on key presence, thus matching when the value is undefined
. By all, I mean all expected values, but any actual values, ie. actual.length
does not have to equal expected.length
.
https://github.com/producthunt/chai-enzyme/blob/master/src/assertions/props.js#L6
It will also pass the values through the chain, allowing (and requiring) the (as you say) absent value to be checked. An ACTUAL absent prop would not pass the initial test in props
, nor would it in my version of prop
.
Specifically, the PR will allow
expect().to.have.prop('third')
to have equivalent results to
expect().to.have.props(['third'])
No matter what the value of props.third
actually is.
Reason (see last two tests)
The result of
props
andprop
are inconsistent for properties who's values areundefined
.I would like to have (give the above example)
to also fail but this may break existing use cases (many tests fail). 😞