diff --git a/jupyter-js-widgets/src/manager-base.ts b/jupyter-js-widgets/src/manager-base.ts index aa7643fd10..25ec6e8ff2 100644 --- a/jupyter-js-widgets/src/manager-base.ts +++ b/jupyter-js-widgets/src/manager-base.ts @@ -347,16 +347,11 @@ abstract class ManagerBase { /** * Close all widgets and empty the widget state. - * @param commlessOnly should only commless widgets be removed - * @return promise that resolves when the widget state is cleared. + * @return Promise that resolves when the widget state is cleared. */ - clear_state(commlessOnly: boolean): Promise { + clear_state(): Promise { return utils.resolvePromisesDict(this._models).then((models) => { - Object.keys(models).forEach((id) => { - if (!commlessOnly || models[id].comm) { - models[id].close(); - } - }); + Object.keys(models).forEach(id => models[id].close()); this._models = {}; }); }; diff --git a/jupyter-js-widgets/test/src/dummy-manager.ts b/jupyter-js-widgets/test/src/dummy-manager.ts index 4443ade5f2..ac8b02bf77 100644 --- a/jupyter-js-widgets/test/src/dummy-manager.ts +++ b/jupyter-js-widgets/test/src/dummy-manager.ts @@ -15,7 +15,6 @@ class MockComm { this.comm_id = `mock-comm-id-${numComms}`; numComms += 1; } - // Somehow the mock comm should trigger a close event? on_close(fn) { this._on_close = fn; }; @@ -24,7 +23,6 @@ class MockComm { if (this._on_close) { this._on_close(); } - console.error(this._on_close); }; send() {}; comm_id: string; diff --git a/jupyter-js-widgets/test/src/manager_test.ts b/jupyter-js-widgets/test/src/manager_test.ts index 277a8aba90..abdb498e1d 100644 --- a/jupyter-js-widgets/test/src/manager_test.ts +++ b/jupyter-js-widgets/test/src/manager_test.ts @@ -149,29 +149,31 @@ describe("ManagerBase", function() { }); describe('clear_state', function() { - it('exists', function() { - expect(this.managerBase.clear_state).to.not.be.undefined; - }); - it('clears the model dictionary', async function() { + it('clears the model dictionary and closes widgets', async function() { let spec = { model_name: 'IntSliderModel', model_module: 'jupyter-js-widgets', model_module_version: '3.0.0', }; - let mSpec1 = { ...spec, comm: new MockComm()}; - let mSpec2 = { ...spec, comm: new MockComm()}; + let comm1 = new MockComm(); + let comm2 = new MockComm(); + sinon.spy(comm1, 'close'); + sinon.spy(comm2, 'close'); + let mSpec1 = { ...spec, comm: comm1}; + let mSpec2 = { ...spec, comm: comm2}; let manager = this.managerBase; let model1 = await manager.new_model(mSpec1); let model2 = await manager.new_model(mSpec2); - let m1 = await manager.get_model(model1.id); expect(await manager.get_model(model1.id)).to.be.equal(model1); expect(await manager.get_model(model2.id)).to.be.equal(model2); await manager.clear_state(); expect(manager.get_model(model1.id)).to.be.undefined; expect(manager.get_model(model2.id)).to.be.undefined; + expect((comm1.close as any).calledOnce).to.be.true; + expect((comm2.close as any).calledOnce).to.be.true; + expect(model1.comm).to.be.undefined; + expect(model2.comm).to.be.undefined; }); - it('clears only commless widgets if comlessOnly is true'); - it('closes the widgets'); }); describe('get_state', function() { diff --git a/jupyter-js-widgets/test/src/widget_date_test.ts b/jupyter-js-widgets/test/src/widget_date_test.ts index 4e739e4fe9..743e8fdfec 100644 --- a/jupyter-js-widgets/test/src/widget_date_test.ts +++ b/jupyter-js-widgets/test/src/widget_date_test.ts @@ -48,7 +48,7 @@ describe('DatePickerView', function() { }); it('initial date value', function() { - const testDate = new Date(2017, 2, 25); // initial date value + const testDate = new Date("2017-02-25"); this.model.set('value', testDate); const options = { model: this.model }; const view = new widgets.DatePickerView(options); @@ -72,7 +72,7 @@ describe('DatePickerView', function() { view.render(); // Simulate setting the date in the datepicker - const testDate = new Date(2015, 2, 22); + const testDate = new Date("2015-02-22"); const datepicker = getDatepicker(view.el); datepicker.valueAsDate = testDate; datepicker.dispatchEvent(new Event('change', {"bubbles":true})); @@ -87,7 +87,7 @@ describe('DatePickerView', function() { const view = new widgets.DatePickerView(options); view.render(); - const testDate = new Date(2015, 2, 22); + const testDate = new Date("2015-02-22"); this.model.set('value', testDate); const datepicker = getDatepicker(view.el); expect(datepicker.valueAsDate.getTime())