Skip to content

fix: prefer native CSS.escape for form values - #737

Open
rajanpanth wants to merge 1 commit into
testing-library:mainfrom
rajanpanth:fix/prefer-native-css-escape
Open

rajanpanth wants to merge 1 commit into
testing-library:mainfrom
rajanpanth:fix/prefer-native-css-escape

Conversation

@rajanpanth

Copy link
Copy Markdown

What this PR does

Fixes #720.

toHaveFormValues now prefers the form document's native CSS.escape implementation when it is available, and falls back to the existing css.escape package otherwise. Using the form's ownerDocument.defaultView keeps this scoped to the DOM instance being asserted, which works better for jsdom/multi-window cases than reading a process-wide global.

The existing dependency remains as a compatibility fallback, so this is a non-breaking first step toward reducing reliance on the package where native support exists.

Validation

  • npm install --no-package-lock --ignore-scripts --prefer-offline
  • npx prettier --check src/to-have-form-values.js src/__tests__/to-have-form-values.js
  • npx eslint src/to-have-form-values.js src/__tests__/to-have-form-values.js
  • CI=1 npm test -- --runInBand src/__tests__/to-have-form-values.js
  • git diff --check

Note: the focused Jest run passes in both configured projects (node and jsdom). It prints the repo's existing Jest config warning about watchPlugins, unrelated to this change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer native CSS.escape (or narrow polyfill) to reduce css.escape npm dependency

1 participant