Commit 512c9d2c authored by Robert Knight's avatar Robert Knight

Add test that `close` is only invoked once

parent 5ab98a3b
......@@ -225,4 +225,24 @@ describe('PortRPC', () => {
assert.calledWith(closeHandler);
});
it('should only invoke "close" handler once', async () => {
const { port1, port2 } = new MessageChannel();
const sender = new PortRPC();
const receiver = new PortRPC();
const closeHandler = sinon.stub();
receiver.on('close', closeHandler);
receiver.connect(port2);
sender.connect(port1);
// Invoke "close" manually. In a real app it will be invoked when the
// window is unloaded and/or the PortRPC is destroyed.
sender.call('close');
sender.call('close');
await waitForMessageDelivery();
assert.calledOnce(closeHandler);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment