|
|
|
|
|
by testingwaters4
1400 days ago
|
|
It's a lovely article and great technology. I am just not so on board with testing the implementation details of such a component. Visual testing always feels off when done with these kinds of testing frameworks (jest, and vitest). As in do you really want to test that a class name is applied to assert that the component rendered with a certain style or visual look? If I change the CSS of the class name to a totally different background colour, then this test
will still pass yet the component is broken because it has the wrong style. Although then I have to answer the question, what is the best way to test for visual changes? Then it would have to be visual snapshots where you save the current state of the test as a screenshot and then assert it matches the previous run. |
|
I think the author doesn't do a good job in explaining what questions such tests are helping to answer. By checking the class name of an element in a component, you are not testing the visual appearance of the component, but its behavior. As in, given a certain set of inputs, the component is expected to produce a certain output. In the author's example, the difference in component's behavior when it receives different `type` props ("success"/"error"/"info") is that it produces a DOM element with different class names. It doesn't tell you anything about whether the component looks right on the screen, but it does confirm that the component is responding to the `type` prop correctly.