question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

global.should = require("chai").should() doesn't work

See original GitHub issue

Not sure why this is or what to do about it, so I wanted to record it so we can look into it later.

Basically, in my Mocha fixture I tried to do

global.should = require("chai").should();

But then when I tried to run

should.not.exist(undefined);

I got a big error saying that “{ … all the properties of the global object … } should not exist”. So it seemed to be picking up Object.prototype.should instead of global.should, which was surprising.

This was under Node 0.8 with Chai 1.1.1, Mocha 1.3.0.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
logicalparadoxcommented, Jul 13, 2012

I know exactly what is happening, and its a bit of a paradox…

Remember, should extends Object.prototype, and global falls into that category. Thus, even though you are assigning global.should the return value of chai.should(), its getting overwritten as the property should. I’m actually surprised this hasn’t shown up as an issue before because it is the same reason you can’t call chai.should() twice on the same export… as chai.should() gets overwritten and then you can do chai.should.have.property('version'). This is why we have chai.Should() as an alias…

Use global.Should = require('chai').Should(). All your problems will go away.

0reactions
nackjicholsoncommented, Mar 13, 2013

Version 1.5.0

Mocha in the browser, with requirejs, and should. Based on this https://github.com/karlbright/requirejs-mocha-chai-bootstrap

I get a big global object that is not null. I can console out the variable I’m testing against, and it says it’s null.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the chai.should function in chai - Snyk
To help you get started, we've selected a few chai.should examples, based on popular ways ... function() { it('does not require new keyword',...
Read more >
Assertion Styles - Chai
Assertion Styles. This section of the guide introduces you to the three different assertion styles that you may use in your testing environment....
Read more >
Chai/Mocha Global/Local - node.js - Stack Overflow
var chai = require('chai'); Apparently globally installed modules are not available to Node by default. Why do so many articles say to load ......
Read more >
Assertion - WebdriverIO
This guide will show examples of how to migrate from Chai if it has been overridden locally and how to migrate from Chai...
Read more >
Chai.js cheatsheet - Devhints
These don't do anything and can be chained. Should not. expect(object).not.equal ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found