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

Merged

Conversation

dharkness
Copy link
Contributor

What

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

Why

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

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

Notes

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.

Housekeeping

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

@codecov
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.

@rluvaton
Copy link
Contributor

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

@keeganwitt
Copy link
Collaborator

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

@rluvaton
Copy link
Contributor

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

@keeganwitt
Copy link
Collaborator

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

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

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
@SimenB
Copy link
Member

SimenB commented Aug 4, 2022

https://github.com/jest-community/jest-extended/releases/tag/v3.0.2

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.

None yet

4 participants