-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow custom assert modules #49
Conversation
This may need some rethinking 🐈
:O Yay. I don't know enough about the code base to see whether or not this is correct; @vdemedes and/or @sindresorhus will look it over, but this looks exciting. |
@jenslind First of all, thanks for PR! How would you implement a support for a.should.equal(b);
should.not.exist(c); |
|
||
// Set custom assert module | ||
Runner.prototype.setAssertModule = function (assertModule) { | ||
Test._setAssertModule(assertModule); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have 2 functions for a one task? You can just leave it as setAssertModule
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean like this?
Runner.prototype.setAssertModule = Test.setAssertModule;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I missed that there are Runner
and Test
there, sorry. I would leave setAssertModule
on Runner
and when you create a new instance of Test
, assign it there - https://github.com/sindresorhus/ava/blob/master/lib/runner.js#L34.
|
@Qix- Most assert libs doesn't have a |
|
@Qix- Oh, I didn't realize. Yeah, that makes things easier. But there still might be other assertion libs where the easy way doesn't work. Maybe we should add support for the most popular assertion lib, so that you can just pass in the main export, and we'll handle whatever's nessecary to decorate it. |
Updated the PR. The following should now work:
Implementing support for |
}); | ||
} | ||
|
||
function setPrototype(el, method) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions inside functions is a really no-go, please separate it out.
@jenslind In my opinion, @sindresorhus what do you think? |
@vdemedes hmm okey so how would you patch the modules? Should we rather aim to add a counter to the module itself and then let |
Remember - not all modules report successful asserts, which is something required for |
The intention was to decorate the assert methods with an assertion counter, not mix them into the test context. I guess we could expose a |
I'd implement something like the following. To use should: var should = chai.should();
var ava = require('ava');
ava.should(should); To use expect: var expect = require('chai').expect;
var ava = require('ava');
ava.expect(expect); or any other module, which does not require custom magic like var assert = require('assert');
var ava = require('ava');
ava.assert(assert); To avoid duplication, we could prefix those methods with ava.setupShould(should);
ava.setupExpect(expect);
ava.setupAssert(assert); |
That seems messy for two reasons:
|
It's to be explicit. If we only have
Not sure I understand what you mean, but this is only for mixing in the assert counter into the assert lib, not the other way. After calling I want to get this moving. What's the minium thing we can do first? Maybe ignore the should/except stuff and just expose a generic |
Allows you to set a custom assert module so it can be used together with
plan()
.#25