global.should = require("chai").should() doesn't work
See original GitHub issueNot 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:
- Created 11 years ago
- Comments:9 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 assigningglobal.should
the return value ofchai.should()
, its getting overwritten as the propertyshould
. I’m actually surprised this hasn’t shown up as an issue before because it is the same reason you can’t callchai.should()
twice on the same export… aschai.should()
gets overwritten and then you can dochai.should.have.property('version')
. This is why we havechai.Should()
as an alias…Use
global.Should = require('chai').Should()
. All your problems will go away.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.