question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow multiple expect() calls within one test

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
djom202commented, Sep 4, 2018

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.

0reactions
dakotacookenmastercommented, Jul 1, 2021

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.

This was very helpful! I can’t believe I didn’t think of something so simple. Thank you so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

chai-as-promised: multiple expect statements in a single test
This allows multiple Chai assertions (and perhaps some other assertion libraries) in the same test and will report on all of the failures....
Read more >
Is it OK to have multiple asserts in a single unit test?
If you need to test multiple fields of a result or multiple results of a single operation, you absolutely should assert all of...
Read more >
Stop requiring only one assertion per unit test
One way to handle this is to refactor the test code into a method that can then be shared between two separate tests....
Read more >
Expect - Jest
The expect function is used every time you want to test a value. You will rarely call expect by itself. Instead, you will...
Read more >
Mocking a JavaScript Class with Jest, two ways to make it easier
For instance, if a test is doing an HTTP call to another server and that server is down for 1 hour, your unit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found