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

Property 'expand' does not exist on type 'MatcherUtils'. #7091

Closed
haldunanil opened this issue Oct 2, 2018 · 10 comments
Closed

Property 'expand' does not exist on type 'MatcherUtils'. #7091

haldunanil opened this issue Oct 2, 2018 · 10 comments

Comments

@haldunanil
Copy link

haldunanil commented Oct 2, 2018

🐛 Bug Report

When using TypeScript 3.1.1 with Jest 23.6.0, I get an error when trying to expand Jest's expect with a custom method.

To Reproduce

    if (pass) {
      ...
    } else {
      const diffString = diff(expected, received, {
        expand: this.expand
      });

      ...
    }

this.expand throws the TS2339 error mentioned in the title.

Expected behavior

this.expand should work as intended.

Link to repl or repo (highly encouraged)

N/A

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 8.9.0 - ~/.nvm/versions/node/v8.9.0/bin/node
    Yarn: 1.9.4 - /usr/local/bin/yarn
    npm: 5.5.1 - ~/.nvm/versions/node/v8.9.0/bin/npm
@rickhanlonii
Copy link
Member

Hey @haldunanil, thanks for using Jest!

If you're able to complete the issue template, I'm happy to re-open and take a look 👍

@haldunanil
Copy link
Author

@rickhanlonii yeah my bad, trigger fingers, submitted too soon. Please have a look now :)

@rickhanlonii
Copy link
Member

Thanks for the deets @haldunanil

Where did you see the usage of this.expand you expect? Is it possible to create a repro to repro?

@rickhanlonii rickhanlonii reopened this Oct 2, 2018
@haldunanil
Copy link
Author

haldunanil commented Oct 2, 2018

this.expand is used here, the full code of the expansion that's throwing the error: https://github.com/haldunanil/jest-contain-object/blob/master/index.js

The this.expand part was inspired by the example in the Jest documentation here: https://jestjs.io/docs/en/expect#custom-matchers-api, the code block that begins with:

const diff = require('jest-diff');
expect.extend({
  toBe(received, expected) {
    const pass = Object.is(received, expected);
...

@SimenB
Copy link
Member

SimenB commented Oct 2, 2018

Seems like an error in whatever TS typings you use - Jest doesn't ship with typings and this.expand is available (added here: https://github.com/facebook/jest/blob/ec382f527e75e0d6932e3e3954187d8a4d6c6240/packages/jest-jasmine2/src/jest_expect.js#L30). Happy to reopen if I'm mistaken!

@SimenB SimenB closed this as completed Oct 2, 2018
@haldunanil
Copy link
Author

@SimenB can you clarify how to use this?

@SimenB
Copy link
Member

SimenB commented Oct 3, 2018

Clarify what? Your typing is wrong, it works. this.expand is a boolean inside of a matcher

@haldunanil
Copy link
Author

I'm not clear on how what the correct typing should look like.

@SimenB
Copy link
Member

SimenB commented Oct 3, 2018

It's a Boolean. Please open up an issue with whatever project you got typings from. Jest does not ship any typings at all, so this is not the correct place to raise an issue for it

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants