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

[Feature] Number of expected assertions #27

Open
jhnns opened this issue Jul 17, 2012 · 2 comments
Open

[Feature] Number of expected assertions #27

jhnns opened this issue Jul 17, 2012 · 2 comments

Comments

@jhnns
Copy link

jhnns commented Jul 17, 2012

I think it is very useful to test for a number of assertions because in asynchronous tests it's a common error that callbacks are accidentally invoked multiple times.

Maybe this way:

expect(someValue).to.be.ok();
expect(someOtherValue).to.be.ok();

expect.numOfTests().to.be(2);

An internal counter counts the number of assertions. numOfTests() just matches the counter with the expected number. After numOfTests() is called the internal counter is reset.

One problem of that approach would be if testing suites run asynchronous tests in parallel. But I'm not sure if that is usual.

What do you think?

@nathanmacinnes
Copy link
Contributor

The problem I see is that you'd have to manually reset it if you hadn't used it in a few test cases. Where you are using separate assertion and test libraries, I think a better way of monitoring the number of times a callback is called is with a counter in the callback, or with a decent mocking framework.

@skeggse
Copy link

skeggse commented Dec 19, 2013

The problem I see is that you'd have to manually reset it if you hadn't used it in a few test cases. Where you are using separate assertion and test libraries, I think a better way of monitoring the number of times a callback is called is with a counter in the callback, or with a decent mocking framework.

Yep. Another option would be to integrate a lightweight spy, like in Jasmine or Sinon. Personally, I like this option better, because it gives you more control.

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

3 participants