These are chat archives for airbnb/enzyme

8th
Nov 2017
Thomas Grainger
@graingert
Nov 08 2017 11:40
@ljharb I don't really understand the point of shallow rendering, I want to test the actual DOM that gets generated. I don't care what components the unit under test calls out to
@palaniichukdmytro why do you need to check the name?
@palaniichukdmytro can't you just use an eslint plugin that enforces a displayName?
Jordan Harband
@ljharb
Nov 08 2017 18:32
@graingert shallow rendering has the most point :-)
like 99% of your tests should be solely shallow-rendered
the actual DOM that gets generated isn't important; testing that is testing react itself - and you're not react
what's important is what react elements each of your components renders
you're supposed to trust that react converts that to HTML properly.
Thomas Grainger
@graingert
Nov 08 2017 19:37
But what happens if I refactor the component? I want to assert that the behaviour hasn't changed
Jordan Harband
@ljharb
Nov 08 2017 19:41
what behavior
and what kind of refactor
so let's say you move things into separate components
those things get shallow unit tested fully
now, all you need to do is modify your component tests to assert, in its shallow render, that instead of rendering a div with some stuff, it renders a SpecialDiv component with the right props
shallow-rendering lets your tests explicitly delegate testing responsibility to the tests of other components