1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
describe('initComplete Option', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
describe('Check the defaults', function() {
dt.html('basic');
let table;
it('Default should not be true', function() {
$('#example').dataTable();
expect($.fn.dataTable.defaults.fnInitComplete).toBe(null);
});
dt.html('basic');
it('Two arguments passed (no Ajax)', function() {
let called = false;
$('#example').dataTable({
initComplete: function() {
called = true;
expect(arguments.length).toBe(2);
expect(typeof arguments[0]).toBe('object');
expect(typeof arguments[1]).toBe('undefined');
}
});
expect(called).toBe(true);
});
dt.html('empty');
it('Two arguments passed (Ajax)', function(done) {
$('#example').DataTable({
ajax: '/base/test/data/data.txt',
columns: dt.getTestColumns(),
initComplete: function() {
expect(arguments.length).toBe(2);
expect(typeof arguments[0]).toBe('object');
expect(typeof arguments[1]).toBe('object');
done();
}
});
});
dt.html('basic');
it('That one argument is the settings object', function() {
let test;
table = $('#example').DataTable({
initComplete: function(settings) {
test = settings;
}
});
expect(test).toBe(table.settings()[0]);
});
dt.html('basic');
let count = 0;
it('initComplete called once on first draw', function() {
count = 0;
table = $('#example').DataTable({
initComplete: function() {
count++;
}
});
expect(count).toBe(1);
});
it('initComplete never called there after', function() {
$('.paginate_button.next').click();
table.page(1).draw();
expect(count).toBe(1);
});
dt.html('basic');
it('Table fully loaded when called (no Ajax)', function() {
count = 0;
$('#example').dataTable({
initComplete: function() {
expect($('#example tbody tr').length).toBe(10);
expect(this.api().rows().count()).toBe(57);
}
});
});
dt.html('empty');
it('Table fully loaded when called (Ajax)', function(done) {
$('#example').DataTable({
ajax: '/base/test/data/data.txt',
columns: dt.getTestColumns(),
initComplete: function() {
expect($('#example tbody tr').length).toBe(10);
expect(this.api().rows().count()).toBe(57);
done();
}
});
});
});
});
|