Issue when using mocha and sinon fake server after upgrading to 2.1.0
Closed this issue · 3 comments
I'm not sure if this issue belongs here, but after upgrading to jsdom-global 2.1.0, sinon fake server does not mock responses. Instead the responses are being sent to the actual server. Pinning the version of jsdom-global to 2.0.0 fixes the issue. Is this something that you have come across?
@dmackhack I had the similar issue with sinon, the workaround is to create fix.js
file and require it with mocha like -r fix
instead of just -r jsdom-global/register
, also I had troubles using sinon
in my tests so I use it globally inside my fix.js
here is it
/*
* registers jsdom globally
* includes sinon
* registers globally XHR
*/
var jsdomGlobal = require('jsdom-global');
var unregisterJsdomGlobal = jsdomGlobal();
// sinon reads it from global, but jsdom doesn't copy it into global
global.XMLHttpRequest = window.XMLHttpRequest;
var sinon = require('sinon');
// sinon-chai reads sinon from window, but node exports it in global
window.sinon = sinon;
module.exports = function globalSinon () {
return function cleanup () {
unregisterJsdomGlobal();
delete window.sinon;
};
};
whoa, nasty workaround. Nonetheless XMLHttpRequest
isn't exported by jsdom-global v2.1.0 (when it should be), so fixing that should at least remove a few lines in that code.
2.1.1 is out now with the XMLHttpRequest fix.
wow cool, it works really great now, thanks a lot