Created
October 20, 2014 22:14
-
-
Save thomd/4d44a8958ce86aa460bd to your computer and use it in GitHub Desktop.
ajax spy with mocha and sinon
This file contains hidden or 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
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