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

Chai Assertion error doesn't have 'operator' attribute #1252

Closed
rpgeeganage opened this issue May 15, 2019 · 7 comments
Closed

Chai Assertion error doesn't have 'operator' attribute #1252

rpgeeganage opened this issue May 15, 2019 · 7 comments

Comments

@rpgeeganage
Copy link
Contributor

rpgeeganage commented May 15, 2019

Hey everyone,
I'm currently working on a feature in jest repo (jestjs/jest#8454).
While I came across that output is as follows. (https://github.com/facebook/jest/pull/8454/files#diff-e6f1eef106ffd32cb2e65acae35856b8R7)

assert.(received, expected)

    Expected value   "hello sunshine"
    Received:
      "hello world"

    Message:
      expected 'hello world' to equal 'hello sunshine'

    Difference:

    - Expected
    + Received

    - hello sunshine
    + hello world

      11 | describe('chai.js assertion library test', () => {
      12 |   it('expect', () => {
    > 13 |     chai.expect('hello world').to.equal('hello sunshine');
         |                                   ^
      14 |   });
      15 | 
      16 |   it('should', () => {

      at Object.equal (__tests__/chai_assertion.js:13:35)

it is because of https://github.com/facebook/jest/blob/master/packages/jest-circus/src/formatNodeAssertErrors.ts#L127, unable to extract the operator.
In https://nodejs.org/api/assert.html#assert_new_assert_assertionerror_options shows a property of operator.

is it this a bug or have I taken a wrong approach?
Thanks a lot.

@rpgeeganage rpgeeganage changed the title Chai Assertion test doesn't have 'operator' attribute Chai Assertion error doesn't have 'operator' attribute May 15, 2019
@keithamus
Copy link
Member

Hey @rpgeeganage thanks for the issue!

We do not use the operator property at all, to my knowledge. I'd happily welcome a PR to add it if you feel so inclined 😄

@rpgeeganage
Copy link
Contributor Author

@keithamus ,
Thank you very much for the clarification.
I would love to spend time on adding this feature to chai. I will look into this and try to open a PR.
Thanks again for a wonderful library.

@astorije
Copy link
Member

astorije commented Jun 3, 2019

Hey @rpgeeganage, thank you so much for helping!

I think I am misunderstanding something though so let me ask: what is the issue with the output you posted above? Is there something missing or incorrect?
I haven't met the operator attribute before, so I'm trying to understand what it's used for and what I'm missing :)

Thanks!

@SimenB
Copy link

SimenB commented Jun 3, 2019

assert.(received, expected) at the top, it should say assert.equal(received, expected) or some such

@rpgeeganage
Copy link
Contributor Author

@astorije ,
As @SimenB says, I came across this issue when I worked with the above-mentioned PR. At the moment, it hides the operator if not set. eg: https://github.com/facebook/jest/blob/de3815f437c31eed6bb5a80ab3f935d49f4dc9c1/packages/jest-circus/src/formatNodeAssertErrors.ts#L94
But In AssertionError, we can set the operator as per the Nodejs spec which I mentioned above.

@astorije
Copy link
Member

astorije commented Jun 9, 2019

assert.(received, expected) at the top, it should say assert.equal(received, expected) or some such

Oooh I missed that part! I was reading the whole thing 3 times but somehow I missed that first line, ahah! Thanks!

@rpgeeganage
Copy link
Contributor Author

Fixed with #1257

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

No branches or pull requests

4 participants