Skip to content
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

Declare matchers for use with expect.not.MATCHER (#385) #386



Copy link


Move asymmetric matcher declarations to a new AsymmetricMatchers interface and extend that to add matchers to Expect and InverseAsymmetricMatchers.


This provides autocompletion when using expect.not, for example:

const value = {
  name: 'foobar',
  name: expect.not.toStartWith('bar')


This may not play nicely with actual TypeScript projects, but I do not have experience with that to verify. I didn't add any unit tests since I didn't change any code. TypeScript tests would be very useful for the project as a whole.


  • Unit tests
  • Documentation is up to date
  • No additional lint warnings
  • Typescript definitions are added/updated where relevant

Copy link

codecov bot commented Nov 29, 2021

Codecov Report

Merging #386 (2a4ac3a) into main (9d5d236) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              main      #386   +/-   ##
  Coverage   100.00%   100.00%           
  Files           71        71           
  Lines          582       582           
  Branches       148       148           
  Hits           582       582           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be7bc8e...2a4ac3a. Read the comment docs.

Copy link

Hey, is there anything blocking here that I can help with? this issue affects me too :)

Copy link

To give me a little more context on this, what autocompletion was this helping enable? With TypeScript projects in In VS Code?

Copy link

not related to vs code but typescript not compiling as he thinks these matchers can't be negated using .not.*

Copy link

types/index.d.ts Outdated
@@ -418,7 +418,7 @@ declare namespace jest {

// noinspection JSUnusedGlobalSymbols
interface Expect {
interface AsymmetricMatchers {
Copy link

Choose a reason for hiding this comment

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

I don't think it's necessary to define this interface, because it's not one that is defined in @types/jest. The AsymmetricMatchers interface that is defined within Jest's native types of Expect, JestExpect, and Jasmine. It is not referenced within any interface itself.

@keeganwitt keeganwitt force-pushed the chore/expose-matchers-on-expect-not branch from ef9b4ae to 3a2218b Compare July 19, 2022 15:52
@keeganwitt keeganwitt force-pushed the chore/expose-matchers-on-expect-not branch from 3a2218b to 2a4ac3a Compare July 19, 2022 15:57
@keeganwitt keeganwitt merged commit 28e5f53 into jest-community:main Jul 19, 2022
12 checks passed
Copy link

SimenB commented Aug 4, 2022

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

Successfully merging this pull request may close these issues.

None yet

4 participants