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

NodeUnit-like expect assertions #912

Closed
jasonkuhrt opened this issue Jun 28, 2013 · 7 comments
Closed

NodeUnit-like expect assertions #912

jasonkuhrt opened this issue Jun 28, 2013 · 7 comments

Comments

@jasonkuhrt
Copy link

NodeUnit's expect feature:

expect(amount) - Specify how many assertions are expected to run within a test. Very useful for ensuring that all your callbacks and assertions are run.

does indeed seem useful. If mocha has developer docs I'd see about hooking this in as a plugin.

@tj
Copy link
Contributor

tj commented Jul 1, 2013

we can't do this sort of thing since we dont couple with any assertion library, but it's pretty easy to do little counters if you need to and do assert(n == 3) for callback checks etc, pretty much the same thing maybe an extra line or two

@tj tj closed this as completed Jul 1, 2013
@jasonkuhrt
Copy link
Author

@visionmedia yeah I know, and this is what I've been doing for testing streams but such tests are verbose enough, and every little line added is getting painful.

I just need to find a way to make a nice little util that does this automatically, but that requires knowing the internals of mocha and an assertion lib, and hope I can make them cooperate. Right now mocha api/internals aren't documented so not likely to do this soon...

@tj
Copy link
Contributor

tj commented Jul 2, 2013

I don't mind the assert(n == 3) style personally, most tests I write end up having a single callback so it either times out or doesn't, but in the cases where you do need something this would work https://github.com/visionmedia/mocha/wiki/Assertion-counting, or if you need to guarantee ordering: https://github.com/visionmedia/co/blob/master/test/thunks.js#L149

@jasonkuhrt
Copy link
Author

@visionmedia thanks for the references

@jasonkuhrt
Copy link
Author

@visionmedia is there a global beforeEach and afterEach hook in mocha? My thinking is that if I can have mocha use a plugin that hooked on like that, I would have the expect function setup for all my tests as long as mocha is run with that plugin, i.e. on the cli via --require.

That would be ideal.

@tj
Copy link
Contributor

tj commented Jul 4, 2013

yup, root-level ones outside of describes() are attached to the root suite named ""

@jasonkuhrt
Copy link
Author

@visionmedia I see, once again thanks for clarifying!. I take it that this example is a demonstration of such global usage https://github.com/visionmedia/mocha/wiki/Assertion-counting

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

2 participants