describe('Core_listen', () => { var id = 'testContainer'; beforeEach(function() { this.$container = $(`
`).appendTo('body'); }); afterEach(function() { if (this.$container) { destroy(); this.$container.remove(); } }); it('should listen to changes when cell is selected', () => { var hot = handsontable(); hot.selectCell(0, 0); expect(hot.isListening()).toEqual(true); }); it('should\'t listen to changes when cell is selected via `selectCell` when `changeListener` argument is `false`', () => { var hot = handsontable(); hot.unlisten(); expect(hot.isListening()).toEqual(false); hot.selectCell(0, 0, undefined, undefined, true, false); expect(hot.isListening()).toEqual(false); }); it('should unlisten changes', () => { var hot = handsontable(); hot.selectCell(0, 0); expect(hot.isListening()).toEqual(true); hot.unlisten(); expect(hot.isListening()).toEqual(false); }); it('should listen to changes, when called after unlisten', () => { var hot = handsontable(); hot.selectCell(0, 0); hot.unlisten(); hot.listen(); expect(hot.isListening()).toEqual(true); }); it('when second instance is created, first should unlisten automatically', () => { var $container1 = $('
').appendTo('body').handsontable(); $container1.handsontable('selectCell', 0, 0); var $container2 = $('
').appendTo('body').handsontable(); $container2.handsontable('selectCell', 0, 0); expect($container1.handsontable('isListening')).toEqual(false); expect($container2.handsontable('isListening')).toEqual(true); $container1.handsontable('destroy'); $container1.remove(); $container2.handsontable('destroy'); $container2.remove(); }); it('when listen is called on first instance, second should unlisten automatically', () => { var $container1 = $('
').appendTo('body').handsontable(); $container1.handsontable('selectCell', 0, 0); var $container2 = $('
').appendTo('body').handsontable(); $container2.handsontable('selectCell', 0, 0); $container1.handsontable('listen'); expect($container1.handsontable('isListening')).toEqual(true); expect($container2.handsontable('isListening')).toEqual(false); $container1.handsontable('destroy'); $container1.remove(); $container2.handsontable('destroy'); $container2.remove(); }); });