Commit f6ca8fad authored by Robert Knight's avatar Robert Knight

Make minor "close" event testing improvements

 - Use asserts to verify that "close" events are not emitted earlier
   than they should be, rather than blindly resetting the close event
   listener stub.
 - Reset the sinon sandbox after each test to ensure any DOM APIs are
   unmocked
parent c23833a4
...@@ -45,6 +45,9 @@ describe('PortRPC', () => { ...@@ -45,6 +45,9 @@ describe('PortRPC', () => {
afterEach(() => { afterEach(() => {
rpc1.destroy(); rpc1.destroy();
rpc2.destroy(); rpc2.destroy();
// Restore any temporarily mocked DOM APIs.
sinon.restore();
}); });
it('should call the method `plusOne` on rpc2', done => { it('should call the method `plusOne` on rpc2', done => {
...@@ -201,10 +204,11 @@ describe('PortRPC', () => { ...@@ -201,10 +204,11 @@ describe('PortRPC', () => {
sender.connect(port1); sender.connect(port1);
await waitForMessageDelivery(); await waitForMessageDelivery();
closeHandler.resetHistory(); assert.notCalled(closeHandler);
sender.destroy(); sender.destroy();
await waitForMessageDelivery(); await waitForMessageDelivery();
assert.calledOnce(closeHandler);
assert.calledWith(closeHandler); assert.calledWith(closeHandler);
}); });
...@@ -219,10 +223,11 @@ describe('PortRPC', () => { ...@@ -219,10 +223,11 @@ describe('PortRPC', () => {
sender.connect(port1); sender.connect(port1);
await waitForMessageDelivery(); await waitForMessageDelivery();
closeHandler.resetHistory(); assert.notCalled(closeHandler);
window.dispatchEvent(new Event('unload')); window.dispatchEvent(new Event('unload'));
await waitForMessageDelivery(); await waitForMessageDelivery();
assert.calledOnce(closeHandler);
assert.calledWith(closeHandler); assert.calledWith(closeHandler);
}); });
...@@ -297,7 +302,7 @@ describe('PortRPC', () => { ...@@ -297,7 +302,7 @@ describe('PortRPC', () => {
sender.connect(transferredPort); sender.connect(transferredPort);
await waitForMessageDelivery(); await waitForMessageDelivery();
closeHandler.resetHistory(); assert.notCalled(closeHandler);
// Emulate the Safari bug by disabling `postMessage` on the sending port // Emulate the Safari bug by disabling `postMessage` on the sending port
// in the original frame. When the port is transferred to the "parent" // in the original frame. When the port is transferred to the "parent"
...@@ -326,7 +331,6 @@ describe('PortRPC', () => { ...@@ -326,7 +331,6 @@ describe('PortRPC', () => {
const removeWorkaround = installPortCloseWorkaroundForSafari(userAgent); const removeWorkaround = installPortCloseWorkaroundForSafari(userAgent);
removeWorkaround(); removeWorkaround();
assert.notCalled(window.addEventListener); assert.notCalled(window.addEventListener);
window.addEventListener.restore();
}); });
}); });
}); });
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