I’m new to tests with React-Jest-Enzyme, but from all the info I collected about it it seems to me that most of the tests actually tests if the React library breaks, and not my actual business logic.
I’ll give you some examples, and please correct me if I’m wrong:
Snapshot testing:
What’s the deal with this strategy?
From what I see it’s main purpose is to catch any unwanted changes to my code. it “stringify” my component tree, and just noticed if any new line breaks / characters were added, right?
so its mostly being used for those cases I could accidently pressed my keyboard? or someone else accidently mess with my code?
Enzyme’s mount/shallow and Jest’s
Most of the examples I saw explaining the way you use those are something like this:
const wrapper = mount(<MyComponeny />)
expect(wrapper.find(‘button’).simulate(‘click)).toHaveBeenCalledTime(1)
What value do I get out of it?
If I simulate a button click with enzyme’s simulate(‘click’)
, then i should expect it would trigger a click event.
what am I testing here exactly? Enzyme’s functionality?
also the setState method enzyme gives us.
if wrapper.setState({value: ‘some value’)}
suppose to change my state, why do I see use cases like this:
wrapper.setState({value: ‘new value’)}
expect(wrapper.state(‘value’)).toBe(‘new value’)
?
why do i need to test the testing framework / extra libraries?
it’s all seems a little bit ambiguous