Skip to content

Instantly share code, notes, and snippets.

@digitalBush
Last active December 14, 2015 07:09
Show Gist options
  • Save digitalBush/5048349 to your computer and use it in GitHub Desktop.
Save digitalBush/5048349 to your computer and use it in GitHub Desktop.
Preview of KO Model Sync
describe('Model Sync',function(){
var Test=ko.Model.extend({urlRoot:'/Foo'});
describe('When fetching a model', function() {
var model = new Test({id:1}),
parseSpy = sinon.spy(model,"parse");
sinon.stub(jQuery, "ajax")
.returns(jQuery.when({foo:"bar"}));
model.fetch();
it('should make the correct AJAX request', function() {
sinon.assert.calledWithMatch(jQuery.ajax,{type:'GET',url:'/Foo/1'});
});
it('should call the model parse method', function() {
parseSpy.calledOnce.should.be.true;
});
it('should set the object values returned from request', function() {
model.foo().should.equal("bar");
});
after(function(){
jQuery.ajax.restore();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment