Created
August 17, 2013 17:22
-
-
Save wtarr/6257879 to your computer and use it in GitHub Desktop.
Qunit test of ko observable array after a (mocked) ajax call
This file contains 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
module("module", { | |
setup: function () { | |
$.mockjax( { | |
url: "*", | |
responseTime: 1, | |
dataType: 'text/json', | |
responseText: [{'name' : 'wally'},{ "name":"molly" }] | |
}); | |
}, | |
teardown: function () { | |
$.mockjaxClear(); | |
} | |
}); | |
test("Test ko observable array after ajax call", function(){ | |
var impl = new MockClass(); | |
ko.applyBindings(impl); | |
impl.add([{'name' : 'wally'}]); | |
stop(); | |
impl.get(); | |
setTimeout(function() | |
{ | |
ok(impl.collect().length == 2); | |
start(); | |
}, 100); | |
}); | |
var MockClass = function(){ | |
var self = this; | |
self.collect = ko.observableArray([]); | |
self.add = function(data){ | |
self.collect.push(data); | |
}; | |
self.get = function() | |
{ | |
$.getJSON( 'goingnowhere', function(data){ | |
self.add(data); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment