9886351b3dff3603415d57430d7c5973513bcf406702f36123ea35d1e7fdec152b8ca0014dc7f89b731a7d8834d2b6166968d97f9e3b6cc7c8766d009ab35a 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. describe('Core_destroy', () => {
  2. var id = 'testContainer';
  3. beforeEach(function() {
  4. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  5. });
  6. afterEach(function() {
  7. if (this.$container) {
  8. destroy();
  9. this.$container.remove();
  10. }
  11. });
  12. it('should remove table from the root element', function() {
  13. handsontable();
  14. destroy();
  15. expect(this.$container.html()).toEqual('');
  16. });
  17. it('should remove events from the root element, document element and window', () => {
  18. var x = handsontable();
  19. expect(x.eventListeners.length > 0).toBeTruthy();
  20. destroy();
  21. expect(x.eventListeners).toBeNull();
  22. $(document.documentElement).off('.copypaste'); // remove copypaste.js listeners, which are not removed by destroy (because copypaste is a singleton for whole page)
  23. });
  24. it('should NOT remove events from document element and window for other Handsontable instances on the page', () => {
  25. // test based on Core_selectionSpec.js (should deselect currently selected cell)
  26. handsontable();
  27. var $tmp = $('<div id="tmp"></div>').appendTo(document.body);
  28. $tmp.handsontable();
  29. $tmp.handsontable('destroy');
  30. $tmp.remove();
  31. selectCell(0, 0);
  32. $('html').simulate('mousedown');
  33. expect(getSelected()).toBeUndefined();
  34. });
  35. });