Skip to content

Migrate testing from enzyme to @shopify/react-testing #4274

@BPScott

Description

@BPScott

Polaris-react has two ways of running tests:

  • The modern way: import {mountWithApp} from 'test-utilities' which uses @shopify/react-testing per this file.
  • The legacy way: import {mountWithAppProvider} from 'test-utilities/legacy' which uses enzyme per this file.

In order to simplify our testing story and only have one way of doing things we should remove all usage of enzyme and test-utilities/legacy, cumulating in removing src/test-utilities/legacy.tsx and all enzyme dependencies.

In order to do this however we need to migrate all the tests that currently use test-utilities/legacy. That's where you come in.

1 Migrating tests

  • Search the codebase for test-utilities/legacy to find imports of that file.
  • Replace import {mountWithAppProvider} from 'test-utilities/legacy' with import {mountWithApp} from 'test-utilities' and migrate the test content so it passes
  • TODO there's probably some docs from "how to to migrate from enzyme to react-testing" that came out of doing this work in web. Hunt them down and link them here.

@vsumner had some codemods that helped auto migrating the web codebase they might cover a lot of use cases

2 Remove foundations

  • Delete src/test-utilities/legacy.tsx
  • Remove any mentions of enzyme in tests/setup and anywhere else in the codebase
  • Remove enzyme / enzyme-adapter-react-16 dependencies from package.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is broken and not working as intended in the system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions