From e21896f5e15111d49ba59a74c12eb182f02ba55e Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Mon, 9 Dec 2024 16:08:13 +0100 Subject: [PATCH] Handle Navigator API (Node 21+) --- integration-test/fake-clock-integration-test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/integration-test/fake-clock-integration-test.js b/integration-test/fake-clock-integration-test.js index cebfeea..8e66779 100644 --- a/integration-test/fake-clock-integration-test.js +++ b/integration-test/fake-clock-integration-test.js @@ -59,7 +59,7 @@ describe("withGlobal", function () { }); describe("globally configured browser objects", function () { - let withGlobal, originalDescriptors; + let withGlobal, originalDescriptors, originalNavigatorDescriptor; // We use a set up function instead of beforeEach to avoid Mocha's check leaks detector function setUpGlobal() { @@ -69,6 +69,11 @@ describe("globally configured browser objects", function () { ); const window = dom.window; + originalNavigatorDescriptor = Object.getOwnPropertyDescriptor( + global, + "navigator", + ); + function makeMutable(descriptor) { descriptor.configurable = true; } @@ -88,6 +93,8 @@ describe("globally configured browser objects", function () { global.window = window; global.document = window.document; + // navigator is a getter, so we need to remove it, as assigning does not work + delete global.navigator; global.navigator = window.navigator; global.requestAnimationFrame = function (callback) { return setTimeout(callback, 0); @@ -114,6 +121,9 @@ describe("globally configured browser objects", function () { delete global.navigator; delete global.requestAnimationFrame; delete global.cancelAnimationFrame; + + // restore + Object.defineProperty(global, "navigator", originalNavigatorDescriptor); } it("correctly instantiates and tears down", function () {