Last active
December 14, 2015 07:09
-
-
Save digitalBush/5048349 to your computer and use it in GitHub Desktop.
Preview of KO Model Sync
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
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