Chai: Chai Assertion error doesn't have 'operator' attribute

Created on 16 May 2019  路  7Comments  路  Source: chaijs/chai

Hey everyone,
I'm currently working on a feature in jest repo (https://github.com/facebook/jest/pull/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.

Most helpful comment

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

All 7 comments

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 馃槃

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

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!

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

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

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leifhanack picture leifhanack  路  4Comments

huaguzheng picture huaguzheng  路  3Comments

meeber picture meeber  路  3Comments

danthegoodman picture danthegoodman  路  3Comments

JuHwon picture JuHwon  路  5Comments