Skip to content

Instantly share code, notes, and snippets.

@thomd
Created October 20, 2014 22:14
Show Gist options
  • Save thomd/4d44a8958ce86aa460bd to your computer and use it in GitHub Desktop.
Save thomd/4d44a8958ce86aa460bd to your computer and use it in GitHub Desktop.
ajax spy with mocha and sinon
var assert = require('assert')
var sinon = require('sinon');
var window = require('jsdom').jsdom().parentWindow
var jquery = require('jquery')(window);
describe('jquery.ajax', function() {
before(function() {
sinon.spy(jquery, 'ajax')
});
after(function() {
jquery.ajax.restore()
});
it('should be used by $.getJSON', function() {
jquery.getJSON('/some/resource')
assert(jquery.ajax.calledOnce)
assert.equal('json', jquery.ajax.getCall(0).args[0].dataType)
assert.equal('/some/resource', jquery.ajax.getCall(0).args[0].url)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment