Chai: Allow multiple expect() calls within one test

Created on 30 Apr 2014  路  4Comments  路  Source: chaijs/chai

Hi there,

are there any plans to support multiple expects in one test (similar to what jasmine offers)?

When:

    it('foo', function () {
      expect(3==2).to.be.true;
      expect(4==3).to.be.true;
      expect(4==2).to.be.true;
    });

Then:
The test run should results in s.th. like:

AssertionError: expected false to be true
   ...
AssertionError: expected false to be true
   ...
AssertionError: expected false to be true
   ...

instead of just one AssertionError.

Regards, Leif

Most helpful comment

Usually I use the & (and) to concatenate the expects that is only one.

expect(3==2).to.be.true &&
expect(4==3).to.be.true &&
expect(4==2).to.be.true;

Also you can use the || (or) too. I hope this help you.

All 4 comments

:+1: That would be a great feature!

Though I am not familiar with the specifics of how Jasmine accomplishes this, my assumption is that they invoke some handler that does not close the loop on the currently running test (instead of throw new AssertionError('...')). Since Chai strives to be runner agnostic, this is the best default behavior.

That being said, if you have a test runner that approaches detecting failures the same way as Jasmine, Chai's Assertion.prototype.assert [ref] method could be overwritten via our Plugin API to invoke that handler instead.

You should start by getting your test runner to implement this functionality, then implement it on the Chai side of things as a plugin. Please keep us updated on your progress and if you run into any issues with Chai's implementation feel free to open another issue referencing the runner's API.

Thanks for the pointers.

Usually I use the & (and) to concatenate the expects that is only one.

expect(3==2).to.be.true &&
expect(4==3).to.be.true &&
expect(4==2).to.be.true;

Also you can use the || (or) too. I hope this help you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jockster picture jockster  路  4Comments

endymion00 picture endymion00  路  3Comments

JuHwon picture JuHwon  路  5Comments

meeber picture meeber  路  3Comments

corybill picture corybill  路  4Comments