testing - Sinon JS "Attempted to wrap ajax which is already wrapped" -



testing - Sinon JS "Attempted to wrap ajax which is already wrapped" -

i got above error message when ran test. below code (i'm using backbone js , jasmine testing). know why happens?

$(function() { describe("category", function() { beforeeach(function() { category = new category; sinon.spy(jquery, "ajax"); } it("should fetch notes", function() { category.set({code: 123}); category.fetchnotes(); expect(category.trigger).tohavebeencalled(); } }) }

you have remove spy after every test. take @ illustration sinon docs:

{ setup: function () { sinon.spy(jquery, "ajax"); }, teardown: function () { jquery.ajax.restore(); // unwraps spy }, "test should inspect jquery.getjson's usage of jquery.ajax": function () { jquery.getjson("/some/resource"); assert(jquery.ajax.calledonce); assertequals("/some/resource", jquery.ajax.getcall(0).args[0].url); assertequals("json", jquery.ajax.getcall(0).args[0].datatype); } }

so in jasmine test should this:

$(function() { describe("category", function() { beforeeach(function() { category = new category; sinon.spy(jquery, "ajax"); } aftereach(function () { jquery.ajax.restore(); }); it("should fetch notes", function() { category.set({code: 123}); category.fetchnotes(); expect(category.trigger).tohavebeencalled(); } }) }

testing backbone.js jasmine sinon

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -