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
better support for assertion libraries #1651
Comments
|
It's an interesting idea, but I think it imposes too rigid of a structure on the way someone writes their tests. For example, I might write a test that makes 0 use of assertions, but throws an exception given some behavior. Furthermore, assertion functions can be mapped to non-standard names. |
|
I would like this behavior, but perhaps not this implementation. something like describe('foo', function() {
it('does stuff', function() {
this.assertions(4);
expect(foo).to.be(bar);
expect(foo).to.be(bar);
expect(foo).to.be(bar);
expect(foo).to.be(bar);
});
});this is similar to nodeunit's implementation |
|
but I suppose the rub here is detecting assertions is difficult |
|
right, it's all coming back to me now. we discussed this in another ticket somewhere. if we want this behavior, we need to write adapters for assertion libraries. the assertion library would need to be "registered": mocha.use(require('chai'));if we're going to do that, we need to make it so people can write more adapters. I don't see this as necessarily bad, as it'd give us the potential for more functionality around assertion libraries--but we can't expect assertion libraries to implement anything for us. |
|
anyway, this needs more thought. #1457 |
|
If we introduced a new API for registering assertion libs, we could cover some of the more popular libraries with adapters, and expose a generic adapter or adapter interface for others to work with. |
|
Would there be other benefits to registering the assertion lib aside from assertion counting? Seems like a lot for only 1 feature. But if there's a few others, then it's prob worth the work. |
|
@danielstjules depends how full-featured the assertion library is! but agreed, this would be a lot for just one feature. |
|
Another benefit from registering the assertion lib would be the ability to make sure that the test doesn't get marked as passing when there are outstanding promises, as that indicates a missing |
|
Enabling the guessing default number of assertions could be option given on the assertion library. It could do the heuristics when given a test function string. In my test files it's not very nice to write |
Mocha could have a simple way to plug in assertion counting, assertion libraries could then reset the counter on beginning of each test.
Default number of assertions could be guessed from simply searching "assert" or some other word provided by assertion library from within the string of the test content.
The text was updated successfully, but these errors were encountered: