Has anyone used Jasmine to test DataTables?
Has anyone used Jasmine to test DataTables?
I'm looking at doing some BDD on my Javascript using Jasmine: http://pivotal.github.com/jasmine/
Searching the forums for "Jasmine" returns 0 results so I'm guessing no one is doing this but thought I'd get some discussion going.
I have a JavaScript object that I use to manage my DataTable which has server-side processing enabled. I'm trying to test a custom fnRender method to make sure it is doing the correct thing. I'm successfully intercepting the ajax call made to the server but not sure how to make sure my fnRender method is getting called with my test data.
Searching the forums for "Jasmine" returns 0 results so I'm guessing no one is doing this but thought I'd get some discussion going.
I have a JavaScript object that I use to manage my DataTable which has server-side processing enabled. I'm trying to test a custom fnRender method to make sure it is doing the correct thing. I'm successfully intercepting the ajax call made to the server but not sure how to make sure my fnRender method is getting called with my test data.
This discussion has been closed.
Replies
Regarding your specific test, I'm not use how Jasmine works exactly, but can you put expects() assertions into the fnRender function itself? Or perhaps have it test what has been rendered (which is what I do in my own unit testing framework)?
Allan
[code]
spyOn($.fn.DataTable.defaults, "fnServerData").andCallFake(function( sUrl, aoData, fnCallback, oSettings ) {
// construct JSON object as it would be returned from server
var json = {
iEcho: 1,
iTotalRecords: 1,
iTotalDisplayRecord: 1,
aaData: [
[1,2,3,4,5]
]
};
// call fnCallback to allow DataTables to do it's thing with the data
fnCallback(json);
}
[/code]
Then I should hopefully be able to put a spy on my custom fnRender method and verify it's return value.
By the way. I want to echo what I've seen said in many posts on this forum...this is an EXCELLENT plugin that was obviously very thoughtfully developed. Thanks, and well done!
Jason