department-of-veterans-affairs / va.gov-team

Public resources for building on and in support of VA.gov. Visit complete Knowledge Hub:
https://depo-platform-documentation.scrollhelp.site/index.html
283 stars 204 forks source link

Linting Rule: no-enzyme-when-hooks #11674

Open billfienberg opened 4 years ago

billfienberg commented 4 years ago

Issue Description

As a developer that is trying to test a hook-based function component, I want to see a linting error in my editor when I try to use Enzyme, so I learn to not use that pattern ASAP.

Background

Until React@16.8, most components were written using class components. Additionally, most components were tested with Enzyme.

Once React@16.8 was released, people started using function components with hooks.

Problem

People run into problems when trying to test hook-based function components with Enzyme because Enzyme doesn't fully support hooks.

Actual example of VFS team member encountering this problem:

Front end tasks

  1. Write the linting rule
  2. Install the linting rule
  3. Configure the linting rule

Acceptance Criteria

Developers see a linting error in their console when they try to test a hook-based function component using Enzyme.


How to configure this issue

mchelen-gov commented 4 years ago

another place to start might be adding a warning about this (and possible workarounds) to https://department-of-veterans-affairs.github.io/veteran-facing-services-tools/getting-started/common-tasks/new-unit-test

erikphansen commented 4 years ago

The issue isn't with Enzyme, it's with shallow mounting. Folks could still use Enzyme's mount and it will work with hooks.

mchelen-gov commented 4 years ago

@erikphansen yup true, maybe we could mention that in docs?