Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: migrate Enzyme tests to React Testing Library#1851

Open
felixrieseberg wants to merge 3 commits intomain from
felixr/enzyme-to-rtl-v2
Open

test: migrate Enzyme tests to React Testing Library #1851
felixrieseberg wants to merge 3 commits intomain from
felixr/enzyme-to-rtl-v2

Conversation

@felixrieseberg
Copy link
Member

@felixrieseberg felixrieseberg commented Feb 10, 2026
edited
Loading

Summary

Migrate all 21 Enzyme test files to React Testing Library. This is a pure test infrastructure change — no source code modifications.

Motivation

Enzyme is unmaintained and has no adapter for React 18+. Migrating to RTL now unblocks a future React 18 upgrade as a clean, separate PR.

Changes

Removed

  • enzyme, enzyme-adapter-react-16, enzyme-to-json, @types/enzyme, @types/enzyme-adapter-react-16
  • Enzyme configuration from tests/setup.ts
  • enzyme-to-json/serializer from vitest.config.ts
  • 20 Enzyme-generated snapshot files

Added/Rewritten (21 files)

All test files in tests/renderer/components/ rewritten using render/screen/userEvent from @testing-library/react instead of shallow/mount from Enzyme. commands-spec.tsx was migrated to RTL (not deleted — it contains unique test coverage).

Test infrastructure

  • tests/setup.ts: Removed Enzyme adapter config
  • vitest.config.ts: Removed Enzyme snapshot serializer
  • rtl-spec/components/commands-address-bar.spec.tsx, commands-publish-button.spec.tsx: Added waitFor/act for MobX observer re-renders affected by the setup changes

Verification

  • tsc --noEmit: 0 errors
  • vitest run: 92 files, 813 passed, 0 failed
  • eslint: 0 errors
  • Still on React 16 — no source changes needed

Replace all 21 Enzyme test files with React Testing Library equivalents.
Remove enzyme, enzyme-adapter-react-16, enzyme-to-json and their @types
packages. Remove Enzyme config from tests/setup.ts and vitest.config.ts.
Delete commands-spec.tsx (RTL equivalents already exist in rtl-spec/).
Delete all Enzyme-generated snapshot files.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

coveralls commented Feb 10, 2026
edited
Loading

Coverage Status

coverage: 79.645% (+0.1%) from 79.539%
when pulling 49e89c9 on felixr/enzyme-to-rtl-v2
into 506ad8f on main.

Copy link
Member

@dsanders11 dsanders11 left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pure test infrastructure change — no source code modifications.

There's a source code modification to src/renderer/components/output.tsx.

commands-spec.tsx (RTL equivalents already exist in rtl-spec/)

Those mentioned tests do not cover what this file was testing (i.e. handleDoubleClick) so removing it is incorrect and reduces existing test coverage.

added crypto.subtle polyfill for jsdom

It's not clear what the motivation for this change was, tests pass without it.


I did an initial pass of reviewing this PR, but the signal-to-noise ratio isn't great because there's a a handful of systemic failings that need to be cleaned up here - some of them are called out by the 45 alerts on this PR.

I've made some inline comments, but in cases where there's lots of occurences of the same issue, I only made a single comment since I can't comment on them all.

  • There's a dozen occurrences of import userEvent from '@testing-library/user-event'; when it should be import { userEvent } from '@testing-library/user-event'; as in our existing RTL tests
  • Some of these refactors are leaving unused imports as a result
  • There's 100+ occurrences of (instance as any) which should just be instance
    • One of the benefits of switching to RTL is instance is typed correctly and we benefit with the type safety.
    • This is also inflating the diff as I see at least a handful of places where it's changing instance to be (instance as any) and that's the only diff
  • Claude sprinkled act throughout the tests, but it's not clear if it's adding any value, or if the tests would work fine without them - we have no existing usage in our other RTL specs
    • This similarly inflates the diff as there are cases where the only change is wrapping an existing line in act(() => { ... }) - I tested removing it in those cases and the tests still pass
  • These changes are pretty inconsistent about using our renderClassComponentWithInstanceRef helper, which provides type safety by ensuring that instance is typed correctly.

felixrieseberg and others added 2 commits February 11, 2026 13:25
- Revert output.tsx source change; provide MosaicContext.Provider in test
- Remove crypto.subtle polyfill from setup.ts (not needed on React 16)
- Migrate commands-spec.tsx to RTL instead of deleting (unique coverage)
- Fix userEvent import: default → named import in all test files
- Use renderClassComponentWithInstanceRef consistently, remove (as any)
- Remove unnecessary act() wrappers
- Revert changed test titles in dialog-bisect-spec.tsx
- Remove unused imports
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add waitFor/act for pre-existing RTL tests that need them for MobX
 observer re-renders
- Remove 103 unnecessary (instance as any) casts; use typed instance
 from renderClassComponentWithInstanceRef. Remaining 17 casts are
 commented (private methods or Readonly<S> bypass).
- Fix no-op tests: bisect command tools, settings unknown page, dialogs
 settings — all now assert meaningful component output.
- Restore dropped coverage: button disabled states, radio ordering,
 file-selected render path, renderItem text verification.
- Remove 8 unnecessary act() wrappers around async methods that don't
 need synchronous state flush, matching rtl-spec/ convention.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
import React from 'react';

import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
Copy link
Member Author

@felixrieseberg felixrieseberg Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these tests needed to be changed once Enzyme went out the window, which is a little counter-intuitive: removing the Enzyme adapter config and snapshot serializer from tests/setup.ts and vitest.config.ts affected timing here, hence the changes in these two files.

I have not yet moved the files over, I suspect we want to do that post-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dsanders11 dsanders11 dsanders11 requested changes

@codebytere codebytere Awaiting requested review from codebytere codebytere is a code owner

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /