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

Using "expect.not.stringContaining" produces a "val.toAsymmetricMatcher is not a function" error #6268

Closed
sangaline opened this issue May 25, 2018 · 3 comments · Fixed by #6272

Comments

@sangaline
Copy link

sangaline commented May 25, 2018

🐛 Bug Report

The example from the documentation for expectnotstringcontaingstring works when the substring isn't contained, but it gives a val.toAsymmetricMatcher is not a function error when the substring is contained. It's expected that the test should fail, but this does not seem like the expected error in this scenario.

To Reproduce

Create a file called string.test.js with the following contents.

describe('not.stringContaining', () => {
  const expected = 'are you?';

  it('matches if the actual string does not contain the expected substring', () => {
    expect('How are you?').toEqual(expect.not.stringContaining(expected));
  });
});

Then run the following.

jest

Expected behavior

The expected behavior is that this would produce an informative error about the substring being contained within the "How are you?" string when it is expected not to be.

Link to repl or repo (highly encouraged)

Here is a link to repl.it, but they're using version 22 and the error is different with that version. On v22 it is

TypeError: Cannot read property 'stringContaining' of undefined

and on v23 it is

TypeError: val.toAsymmetricMatcher is not a function

Run npx envinfo --preset jest

Paste the results here:

npx: installed 1 in 1.148s

  System:
    OS: Linux 4.9 Amazon Linux AMI 2017.09
    CPU: x64 Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
  Binaries:
    Node: 9.4.0 - ~/.nvm/versions/node/v9.4.0/bin/node
    Yarn: 1.7.0 - ~/.nvm/versions/node/v9.4.0/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v9.4.0/bin/npm
  npmPackages:
    jest: ^23.0.0 => 23.0.0 
@SimenB
Copy link
Member

SimenB commented May 26, 2018

Thanks for the report! Opened up a PR for it: #6272

@jayarjo
Copy link

jayarjo commented Feb 22, 2021

How to mitigate that error - TypeError: val.toAsymmetricMatcher is not a function in a custom (user defined) matcher?

@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 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants