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

use should() with chai #14

Closed
shaunc opened this issue Dec 7, 2014 · 8 comments
Closed

use should() with chai #14

shaunc opened this issue Dec 7, 2014 · 8 comments

Comments

@shaunc
Copy link

shaunc commented Dec 7, 2014

I'm having trouble using should() with chai -- can't seem to import it? Could you add to the doc? Also, if we want to globally initialize chai.should(), where should the code go?

@shaunc
Copy link
Author

shaunc commented Dec 7, 2014

Aha ... putting into test-helper.js works:

 // Declare `expect` as a global here instead of as a var in individual tests.
 // This avoids jshint warnings re: `Redefinition of 'expect'`.
 window.expect = chai.expect;
 window.should = chai.should();

@dgeb
Copy link
Member

dgeb commented Dec 7, 2014

Glad you sorted it. Did you mean window.should = chai.should; instead of window.should = chai.should(); ?

Because the blueprints all use expect, I'm on the fence as to whether to include this declaration for everyone or just provide instructions in the README.

@shaunc
Copy link
Author

shaunc commented Dec 7, 2014

chai.should needs to be called once globally in order to inject "should" into Object.proto. Having this available doesn't preclude the use of expect, of course. This would seem like the place to do it. Of course you could split the difference and just have it available. (Perhaps there is some test so test code could include something such as:

if (typeof should === 'function') window.should = should();

in all their tests.) I at least haven't hit any drawbacks or collisions with having .should everywhere. In the best case, availability of should would be configurable somehow. Is EmberENV available here?

@shaunc
Copy link
Author

shaunc commented Dec 7, 2014

btw also using sinon -- found http://knomedia.github.io/blog/2014/05/31/using-ember-cli-and-sinon/ helpful for install, but is a bit of a winding path. Could there be blueprints for "install some (arbitrary) test package"?

@tonycoco
Copy link

@jonathanKingston
Copy link
Member

👍 to exposing Chai internals in each test (which seems to be the way ember-cli is suggesting to write qunit tests).

Personally for me assert has the most sane syntax as for BDD code a real BDD assertion library should be used external to these tests where by business can drive the tests like cucumber.

So I would like to be able to do:

import { assert } from 'ember-mocha';

Or similar.

@dgeb
Copy link
Member

dgeb commented Feb 22, 2015

So, we've just introduced a chai module in ember-mocha that exports expect and assert. Both @rwjblue and I were wary to export should alongside these two, as discussed here: #37 (comment)

To semi-officially support should, we could just add a suggestion to the README to add window.chai.should(); to test-helper.js. Of course accessing a global like this is pretty hackish when everything else is modularized.

We could also export should through a new shim module in ember-mocha (perhaps chai-should?). If anyone really wants this, let's have the discussion here or in ember-mocha. Of course, such a shim could be added to a completely separate lib even if we decide against including it in ember-mocha.

@Turbo87
Copy link
Member

Turbo87 commented Nov 28, 2016

This should be covered by ember-cli-chai now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants