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

should.not.exist() checks existence of global object #260

Closed
bguezzie opened this issue May 1, 2014 · 2 comments
Closed

should.not.exist() checks existence of global object #260

bguezzie opened this issue May 1, 2014 · 2 comments

Comments

@bguezzie
Copy link

bguezzie commented May 1, 2014

I'm trying to do a simple existence check:

should.not.exist(foo);  // foo is undefined, so this should pass

But my whole Node environment blows up unexpectedly. After stepping into the code, I've found that the existence check is looking at the 'object' flag on the Assertion, which is set to the global object. Effectively, this means that the above instance check is comparing the global object against null, which fails (the Node implosion is somehow related to attempting to format the entire global object as a string in the assertion error message...separate issue).

Again, I've confirmed that this is the comparison actually happening. In core/assertions.js on line 301 (using the latest version of Chai published via npm), it is indeed comparing null to the global object. At no point do I ever see my 'foo' come into play.

Is there something I'm missing here? I've double checked that I'm calling require("chai").should(); and all my other should-based statements work just fine.

If there are any other details you need, please let me know.

@logicalparadox
Copy link
Member

It sounds like your are not initializing the should interface correctly. You should be doing:

require('chai').should(); // wrong
var should = require('chai').should(); // correct

If you don't "locally" scope the should variable then it operates off of global.should, which is why the object flag for Assertion is the global object and everything explodes.

@bguezzie
Copy link
Author

bguezzie commented May 1, 2014

Ah, okay! That did indeed fix the issue. Many thanks :)

---Brian

On Thu, May 1, 2014 at 3:01 PM, Jake Luer notifications@github.com wrote:

It sounds like your are not initializing the should interface correctly.
You should be doing:

require('chai').should(); // wrongvar should = require('chai').should(); // correct

If you don't "locally" scope the should variable then it operates off of
global.should, which is why the object flag for Assertion is the global
object and everything explodes.


Reply to this email directly or view it on GitHubhttps://github.com//issues/260#issuecomment-41950278
.

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