Skip to content

Improve chai support (with detailed output, to match jest exceptions)ย #8152

@G-Rath

Description

@G-Rath

๐Ÿš€ Feature Proposal

A clear and concise description of what the feature is.

When using jest matchers, we get nice output:

describe('atest', () => {
  it('tests something', () => {
    expect('hello world').toEqual('hello sunshine');
  });
});
  โ— atest โ€บ tests something

    expect(received).toEqual(expected)

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

      at Object.it (phone-number.test.ts:59:27)
          at new Promise (<anonymous>)
      at process._tickCallback (internal/process/next_tick.js:68:7)

ss+(2019-03-20+at+07 58 00)

If I use chai#expect matchers:

describe('atest', () => {
  it('tests something', () => {
    chai.expect('hello world').to.equal('hello sunshine');
  });
});
  โ— atest โ€บ tests something

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

      at Object.it (phone-number.test.ts:60:35)
          at new Promise (<anonymous>)
      at process._tickCallback (internal/process/next_tick.js:68:7)

ss+(2019-03-20+at+08 00 46)

When I run the same chai test in mocha:

  2) atest
       tests something:

      AssertionError: expected 'hello world' to equal 'hello sunshine'
      + expected - actual

      -hello world
      +hello sunshine

      at Context.<anonymous> (test\src\utilities\omitFrom.test.ts:31:49)

ss+(2019-03-20+at+07 56 14)

From my understanding, the issue lies with Jest not taking any advantage of information provided by Chai, as Chai exposes expected & received information as part of the thrown assertion error, meaning it's on the testing system to utilise that information.

Personally, this is the biggest showstopper for me switching to Jest :)


In addition, WebStorm shows a diff for some Jest matches, but not for chai matchers (whereas it does show a diff for chai in mocha, as evident in my previous screenshot).

I'm not sure what's required for this to be supported, but figure its related to the way Jest formats its output? (@segrey it'd be great if you could provide any info on this, if possible).

My efforts right now are hampered somewhat by #8118, so I can't be sure of how functional my test suites are right now ๐Ÿ˜‚

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      โšก