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

Issue when using expect.not #5848

Closed
holgergp opened this issue Mar 21, 2018 · 12 comments
Closed

Issue when using expect.not #5848

holgergp opened this issue Mar 21, 2018 · 12 comments

Comments

@holgergp
Copy link

I am experiencing a strange behavior using expect.not, which may be a bug.
not seems not to defined on the expect object anymore.

I pasted a simple example from https://facebook.github.io/jest/docs/en/expect.html#expectnotstringcontainingstring
into a repl.it demo: https://repl.it/@holgergp/testing-not

The output of the test:

Jest v22.1.2 node v7.4.0 linux/amd64
   
 FAIL  ./not-test.js
  not.stringContaining
    ✕ matches if the actual string does not contain the expected substring (7ms)

  ● not.stringContaining › matches if the actual string does not contain the expected substring

    TypeError: Cannot read property 'stringContaining' of undefined

      3 | 
      4 |   it('matches if the actual string does not contain the expected substring', () => {
    > 5 |     expect('How are you?').toEqual(expect.not.stringContaining(expected));
      6 |   });
      7 | });
      
      at Object.it (not-test.js:5:46)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        0.913s
Ran all test suites.
exit status 1
@mattphillips
Copy link
Contributor

Hey @holgergp this seems to be an issue with the docs containing new features that haven't been published yet.

From what I can see .not asymmetric matchers were added in #5517 but haven't been published yet.

@mattphillips
Copy link
Contributor

@SimenB I'm working on a PR to fix this now

@SimenB
Copy link
Member

SimenB commented Mar 21, 2018

@mattphillips
Copy link
Contributor

@SimenB PR #5853 😄

@holgergp
Copy link
Author

Thank you!

@SimenB
Copy link
Member

SimenB commented May 2, 2018

Imma call this fixed

@SimenB SimenB closed this as completed May 2, 2018
@gurbraj
Copy link

gurbraj commented Aug 31, 2018

Any suggestions on what to use instead? =)

@gurbraj
Copy link

gurbraj commented Aug 31, 2018

I made this solution but am not particularly fond of it:

    try {
      expect(app.html()).toEqual(expect.stringContaining('你好'));
    } catch (error) {
      expect(true).toEqual(true);
    }
    expect.assertions(2);

@SimenB
Copy link
Member

SimenB commented Sep 1, 2018

@gurbraj what do you mean? expect.not landed in Jest 23.0.0 so it's available now

@webdevbyjoss
Copy link

How the expression should look like for the Jest before 23.0.0?

@wasinsandiego
Copy link

wasinsandiego commented Nov 28, 2018

In case you are on a version < 23.0.0 here's what I ended up doing.

Example similar to the docs for not.stringContaining.

describe('not.toEqual using `expect.stringContaining`', () => {
  const expected = 'Hello world!';

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

If anyone sees any issue with this, please let me know.

@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.
Projects
None yet
Development

No branches or pull requests

6 participants