Skip to content

Issue-143: Fix Jest bugs #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 5, 2025
Merged

Conversation

benpbolton
Copy link
Contributor

@benpbolton benpbolton commented May 29, 2025

Summary

Fixes #143

This pull request attempts to ensure Jest works seamlessly after configuration. It includes bumps to dependencies for testing React and WordPress block editor components.

Note

Unfortunately, I was unable to test this directly due to the work in #158 to remove tests (npm run test via turbo will find no acceptable tests to run with the current configuration). Thanks to @kevinfodness for the sample tests... provided: (1) there is an appropriate npm run test script within the theme/plugins and (2) there are items to test, jest tests are confirmed working.

CleanShot 2025-06-04 at 13 57 52

Changes

  • Upgraded @testing-library packages to the latest versions and updated other related dependencies to ensure compatibility.
  • Installed react and react-dom at version 18 to resolve peer dependency issues with @testing-library.
  • Explicitly included jest-environment-jsdom to ensure DOM-related tests work correctly, as it is no longer included by default in Jest 28+.
  • Explicitly included @testing-library/dom
  • Added a module name mapper for styles using identity-obj-proxy to mock CSS, LESS, SCSS, and SASS imports in tests.
  • Removed the Babel configuration for Jest and replaced it with ts-jest for native TypeScript compatibility.
  • Ensured ts-node is explicitly required for development and Jest configuration.

@benpbolton benpbolton added bug Something isn't working javascript Requires understanding JavaScript typescript Requires understanding TypeScript labels May 29, 2025
v5 and earlier: use @testing-library/jest-dom/extend-expect In @testing-library/jest-dom v6+: use just @testing-library/jest-dom  Since we're using v6.6.3, we should use the simpler import.
Starting from Jest 28, jest-environment-jsdom is no longer included by default in the Jest package. It needs to be installed separately when you want to test code that interacts with the DOM (like React components). Since we're looking at React and WordPress block editor components, we may need a DOM environment for testing.
... replacing that with a transform to `ts-jest` the files first...
including testing-library/react
@benpbolton benpbolton marked this pull request as ready for review May 29, 2025 19:01
@benpbolton benpbolton requested a review from a team as a code owner May 29, 2025 19:01
@benpbolton benpbolton mentioned this pull request May 29, 2025
@benpbolton benpbolton merged commit ba598b3 into production Jun 5, 2025
1 check passed
@benpbolton benpbolton deleted the fix/issue-143/fix-jest-bugs branch June 5, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working javascript Requires understanding JavaScript typescript Requires understanding TypeScript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Jest bugs
2 participants