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

better support for assertion libraries #1651

Closed
Ciantic opened this issue Apr 13, 2015 · 11 comments
Closed

better support for assertion libraries #1651

Ciantic opened this issue Apr 13, 2015 · 11 comments
Labels
future needs to wait nice to have enhancement proposal of low priority status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior type: feature enhancement proposal

Comments

@Ciantic
Copy link

Ciantic commented Apr 13, 2015

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.

@danielstjules
Copy link
Contributor

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. var foo = require('assert'); It would be difficult to enforce anything other than simple cases (looking for expect, assert and should) without a heavy implementation (parsing AST, etc).

@boneskull
Copy link
Member

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

@boneskull
Copy link
Member

but I suppose the rub here is detecting assertions is difficult

@boneskull
Copy link
Member

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.

@boneskull
Copy link
Member

anyway, this needs more thought. #1457

@boneskull boneskull changed the title pluggable assertion counting better support for assertion libraries Apr 26, 2015
@boneskull boneskull added type: feature enhancement proposal future needs to wait labels Apr 26, 2015
@danielstjules
Copy link
Contributor

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.

@danielstjules
Copy link
Contributor

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.

@boneskull
Copy link
Member

@danielstjules depends how full-featured the assertion library is! but agreed, this would be a lot for just one feature.

@papandreou
Copy link
Contributor

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 return of a promise. At least this would be a great help for the unexpected assertion library, which uses promises internally to orchestrate asynchronous tests, and probably also chai-as-promised.

@Ciantic
Copy link
Author

Ciantic commented Apr 27, 2015

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 this.assertions(n) at the beginning of each test, when all of the tests has exactly same number of assertions as simply searching "assert" from within a test function string.

@boneskull boneskull added the next label Jan 7, 2016
@boneskull boneskull added major-release future needs to wait and removed future needs to wait next labels May 22, 2016
@boneskull boneskull added the nice to have enhancement proposal of low priority label Oct 18, 2017
@JoshuaKGoldberg
Copy link
Member

anyway, this needs more thought. #1457

Indeed it does. Per #2044, I think this specific proposal is one we can close out. Having a plugin API such as in #1457 would be the right way to provide users the means to do this themselves.

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg added the status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior label Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future needs to wait nice to have enhancement proposal of low priority status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior type: feature enhancement proposal
Projects
None yet
Development

No branches or pull requests

5 participants