Skip to content

fix: match literal substrings in toIncludeRepeated - #994

Merged
keeganwitt merged 2 commits into
jest-community:mainfrom
anticipate218:fix/literal-repeated-substrings
Nov 25, 2026
Merged

keeganwitt merged 2 commits into
jest-community:mainfrom
anticipate218:fix/literal-repeated-substrings

Conversation

@anticipate218

Copy link
Copy Markdown
Contributor

What

Escape regular expression metacharacters in the substring passed to toIncludeRepeated. Add regression tests, clarify the literal matching behavior in the documentation, and include a patch changeset.

Why

Closes #195.

The matcher documents a string substring, but currently constructs a regular expression from it. For example, expect('a..').toIncludeRepeated('.', 2) fails because the dot also matches a, while a substring such as [ throws a regular expression syntax error. These inputs now count literal, non-overlapping occurrences. Existing empty-substring behavior is preserved.

Notes

Validation on Windows with Node.js 24.14.1, Yarn 4.19.0, and the unchanged lockfile (Jest 30.5.2):

  • The regression file against the original implementation: 5 failures and 10 passes.
  • yarn test:coverage --runInBand: 79 suites, 914 tests, and 359 snapshots passed; all coverage thresholds remain at 100%.
  • yarn build, yarn typecheck, and Prettier checks for the changed files passed. The built package also passed 16 assertions covering eight substring cases through Jest's expect.
  • Full yarn lint passed with the repository's LF bytes for the unchanged vitest.d.mts. The default Windows checkout reports the same 15 CRLF formatting errors before and after this change. The file was restored after validation and is not changed in this PR.
  • yarn test:vitest with npm 11.20.0: 13 Vitest 5 tests passed; TypeScript Bundler/NodeNext checks, native ESM/CommonJS loading, and rejection of invalid matcher usage passed.

The other Node.js/Jest/OS matrix combinations and the Docusaurus website build were not run.

AI assistance was used to investigate the issue, implement the change and tests, and run the checks described above.

Housekeeping

  • Unit tests
  • Documentation is up to date
  • No additional lint warnings
  • TypeScript definitions are unchanged because the public API is unchanged

@changeset-bot

changeset-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 21675a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jest-extended Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (128f4a9) to head (21675a1).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #994   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           80        80           
  Lines          914       911    -3     
  Branches       341       339    -2     
=========================================
- Hits           914       911    -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@keeganwitt

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

@keeganwitt
keeganwitt merged commit 7d41bd3 into jest-community:main Nov 25, 2026
26 checks passed
@anticipate218

Copy link
Copy Markdown
Contributor Author

Thanks @keeganwitt for the review, for adding the [.] → . migration note to the changeset, and for merging!

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.

expect('a..').toIncludeRepeated('.', 2); does not work

2 participants