Created
July 11, 2017 11:31
-
-
Save ramzesucr/ecbf6b397c4b3a44727bc208d6f7a901 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jsdom from 'jsdom' | |
import chai from 'chai' | |
import chaiSpies from 'chai-spies' | |
import chaiSubset from 'chai-subset' | |
import chaiAsPromised from 'chai-as-promised' | |
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>') | |
const win = doc.defaultView | |
const localStorage = { | |
getItem: function (attr) { | |
return this[attr] | |
}, | |
setItem: function (attr, val) { | |
this[attr] = val | |
} | |
} | |
global.document = doc | |
global.window = win | |
global.localStorage = localStorage | |
/** | |
* We also need to hoist all the window attributes to Node's global object | |
* so that these attributes can be used without 'window.' (just like it happens | |
* in a web browser). | |
*/ | |
globalExport(window) | |
globalExport( | |
{ | |
__CONFIG_VAR__: 'something' | |
} | |
) | |
function globalExport (obj) { | |
Object.keys(obj).forEach((key) => { | |
if (!(key in global)) { | |
global[key] = obj[key] | |
} | |
}) | |
} | |
// Chai plugins | |
chai.use(chaiSpies) | |
chai.use(chaiSubset) | |
chai.use(chaiAsPromised) | |
global.expect = chai.expect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment