I've recently starting programming. I'm on a team who is programming in React and is using Enzyme, Mocha and Chai for unit testing. See package versions below.
My team insists that the unit test file for each component should have the following test:
beforeEach(() => {
component = mount(<MyComponent />)
})
it('renders with correct properties', () => {
component.setProps({
height: 100,
width: 500,
placeholder: 'Some value here'
})
expect(component.prop('height')).to.equal(100)
expect(component.prop('width')).to.equal(500)
expect(component.prop('placeholder')).to.equal('Some value here')
})
That's the end of the test. To me, this test looks like it's just testing that React sets the props. I feel we can trust what React is doing and instead should be testing how we use React to render our component. I'd rather test the affects of the prop values on other props, state, and how the component renders as a result of the props.
But I'm new and my team thinks I'm wrong in my concern, so I thought I'd check around: Is there value in the above test case that I'm missing? Is it good practice?
Related Questions
- Best practice on setting props in unit tests (also my question)
Packages
- "enzyme": "^3.3.0",
- "enzyme-adapter-react-16": "^1.1.1",
- "mocha": "^5.0.0",
- "chai": "3.5.0"