From b61e1fd69ff8e4f955335e48e74ab9f170583525 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 1 Dec 2016 14:41:34 -0800 Subject: [PATCH] Add spec for error on removing all IPC listeners --- spec/api-ipc-spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index bc286dd17c37..4d368134469b 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -495,4 +495,26 @@ describe('ipc module', function () { assert.equal(w.listenerCount('test'), 0) }) }) + + it('throws an error when removing all the listeners', () => { + ipcMain.on('test-event', () => {}) + assert.equal(ipcMain.listenerCount('test-event'), 1) + + ipcRenderer.on('test-event', () => {}) + assert.equal(ipcRenderer.listenerCount('test-event'), 1) + + assert.throws(() => { + ipcMain.removeAllListeners() + }, /Removing all listeners from ipcMain will make Electron internals stop working/) + + assert.throws(() => { + ipcRenderer.removeAllListeners() + }, /Removing all listeners from ipcRenderer will make Electron internals stop working/) + + ipcMain.removeAllListeners('test-event') + assert.equal(ipcMain.listenerCount('test-event'), 0) + + ipcRenderer.removeAllListeners('test-event') + assert.equal(ipcRenderer.listenerCount('test-event'), 0) + }) })