Given this code:
showForm = function (url) { return $.get(url, function (html) { $('body').append(); }); };
When using sinon.js , jQuery.mockjax.js and expect.js , I have the following passing test:
it("showForm calls jQuery.append", function () { $.mockjax({ url: '/fake' }); var spy = sinon.spy($.fn, "append"); presenter.showForm('/fake'); setTimeout(function () { expect(spy.called).to.be.equal(true); }, 1000); });
Using the setTimeout function to wait for a callback from the asynchronous smell of $.get bad, and this will slow down my test suite if I do too much.
However, I feel that the intention is clear enough, and it looks like he is definitely checking what I want.
Is there a better way and can you explain what is happening in your answer?
source share