docs: Make ipcRenderer and ipcMain listener API docs consistent (#44651)
* docs: Make ipcRenderer and ipcMain listener API docs consistent * test: add some unit tests for ipcRenderer/ipcMain listener behavior * fix: Mark on/off methods as primary and addListener/removeListener as aliases * fix: clear all listeners before running ipcMain removeAllListeners tests
This commit is contained in:
parent
aa7a5e6ca9
commit
10d967028a
4 changed files with 86 additions and 10 deletions
|
@ -18,6 +18,7 @@ describe('ipcRenderer module', () => {
|
|||
}
|
||||
});
|
||||
await w.loadURL('about:blank');
|
||||
w.webContents.on('console-message', (event, ...args) => console.error(...args));
|
||||
});
|
||||
after(async () => {
|
||||
await closeWindow(w);
|
||||
|
@ -144,6 +145,40 @@ describe('ipcRenderer module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('ipcRenderer.removeAllListeners', () => {
|
||||
it('removes only the given channel', async () => {
|
||||
const result = await w.webContents.executeJavaScript(`
|
||||
(() => {
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
ipcRenderer.on('channel1', () => {});
|
||||
ipcRenderer.on('channel2', () => {});
|
||||
|
||||
ipcRenderer.removeAllListeners('channel1');
|
||||
|
||||
return ipcRenderer.eventNames();
|
||||
})()
|
||||
`);
|
||||
expect(result).to.deep.equal(['channel2']);
|
||||
});
|
||||
|
||||
it('removes all channels if no channel is specified', async () => {
|
||||
const result = await w.webContents.executeJavaScript(`
|
||||
(() => {
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
ipcRenderer.on('channel1', () => {});
|
||||
ipcRenderer.on('channel2', () => {});
|
||||
|
||||
ipcRenderer.removeAllListeners();
|
||||
|
||||
return ipcRenderer.eventNames();
|
||||
})()
|
||||
`);
|
||||
expect(result).to.deep.equal([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('after context is released', () => {
|
||||
it('throws an exception', async () => {
|
||||
const error = await w.webContents.executeJavaScript(`(${() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue