Skip to content

Instantly share code, notes, and snippets.

@andrei-cacio
Last active June 13, 2016 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrei-cacio/cda635df0897cd9ce3ea926f11af2ba3 to your computer and use it in GitHub Desktop.
Save andrei-cacio/cda635df0897cd9ce3ea926f11af2ba3 to your computer and use it in GitHub Desktop.
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