Skip to content
Permalink
Browse files

Don't start timers after the window has closed

Fixes #1893.
  • Loading branch information...
Enverbalalic authored and domenic committed Jul 3, 2017
1 parent c35298b commit 3f306bea5362aceb2a219a2e98ff96a7464d2f19
Showing with 20 additions and 0 deletions.
  1. +3 −0 lib/jsdom/browser/Window.js
  2. +17 −0 test/api/from-outside.js
@@ -527,6 +527,9 @@ function matchesDontThrow(el, selector) {
}

function startTimer(window, startFn, stopFn, timerId, callback, ms, args) {
if (!window || !window._document) {
return undefined;
}
if (typeof callback !== "function") {
const code = String(callback);
callback = window._globalProxy.eval.bind(window, code + `\n//# sourceURL=${window.location.href}`);
@@ -0,0 +1,17 @@
"use strict";
const { assert } = require("chai");
const { describe, it } = require("mocha-sugar-free");
const { JSDOM } = require("../..");

describe("Test cases only possible to test from the outside", () => {
it("should not register timer after window.close() called", () => {
const dom = new JSDOM();
const window = dom.window;

assert.notEqual(window.setTimeout(() => {}, 100), undefined);

window.close();

assert.equal(window.setTimeout(() => {}), undefined);
});
});

3 comments on commit 3f306be

@vkarpov15

This comment has been minimized.

Copy link

replied Nov 15, 2018

Is there a reason why this fails silently instead of throwing an error?

@domenic

This comment has been minimized.

Copy link
Member

replied Nov 15, 2018

That's how browsers work.

@vkarpov15

This comment has been minimized.

Copy link

replied Nov 16, 2018

Thanks for responding, technically you're right:

image

image

This behavior just sucks for my use case :( Thanks for the info.

Please sign in to comment.
You can’t perform that action at this time.