Last active
June 13, 2016 07:38
-
-
Save andrei-cacio/cda635df0897cd9ce3ea926f11af2ba3 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
const sinon = require('sinon'); | |
const fakeDOM = require('jsdom').jsdom(); | |
let nodeJquery = null; | |
let jquerySpies = null; | |
export function getJquery() { | |
if (!nodeJquery) { | |
nodeJquery = require('jquery')(fakeDOM.defaultView); | |
} | |
return nodeJquery; | |
} | |
export function getJquerySpies() { | |
if (!jquerySpies) { | |
jquerySpies = {}; | |
Object.keys(nodeJquery.prototype).forEach(method => { | |
if (typeof nodeJquery.prototype[method] === 'function') { | |
jquerySpies[method] = sinon.spy(nodeJquery.prototype, method); | |
} | |
}); | |
} | |
return jquerySpies; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment