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
|
describe('core - events - destroy', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
let table;
let params;
describe('Check the defaults', function() {
dt.html('basic');
it('Called before the destroy', function() {
let count;
table = $('#example').DataTable();
table.on('destroy.dt', function() {
params = arguments;
count = $('div.dataTables_filter').length;
});
table.destroy();
expect(count).toBe(1);
expect($('div.dataTables_filter').length).toBe(0);
});
it('Called with expected parameters', function() {
expect(params.length).toBe(2);
expect(params[0] instanceof $.Event).toBe(true);
expect(params[1]).toBe(table.settings()[0]);
});
});
describe('Functional tests', function() {
let count = 0;
let length;
dt.html('basic');
it('Not called on initial draw', function() {
table = $('#example').DataTable();
table.on('destroy.dt', function() {
count++;
});
expect(count).toBe(0);
});
it('Called when API deletes table but leaves in DOM', function() {
table.destroy(false);
expect(count).toBe(1);
});
dt.html('basic');
it('Called when table deleted from the DOM', function() {
table = $('#example').DataTable();
table.on('destroy.dt', function() {
count++;
});
table.destroy(true);
expect(count).toBe(2);
});
dt.html('basic');
it('Called when initialisation option destroys table', function() {
table = $('#example').DataTable();
table.on('destroy.dt', function() {
count++;
});
$('#example').DataTable({
destroy: true
});
expect(count).toBe(3);
});
});
});
|