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
Post a Comment