Write ESLint rule to prevent creation of hard-to-read Jest snapshots
Jest's toMatchSnapshot()
matcher is used often in GitLab to check components render as expected. When passed a string (e.g., from wrapper.html()
, the string is emitted as the snapshot directly without any (or much) prettification, which leads to hard-to-read snapshots, like these.
Instead, wrapper.element
should be passed, which produced much more readable snapshots.
To prevent such snapshots in the future, we could write an ESLint rule to prevent calls like expect(wrapper.html()).toMatchSnapshot()
, and recommend that it be re-written as expect(wrapper.element).toMatchSnapshot()
.