Skip to content

Commit

Permalink
Handle Navigator API (Node 21+)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Dec 9, 2024
1 parent fea39ca commit e21896f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion integration-test/fake-clock-integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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 () {
Expand Down

0 comments on commit e21896f

Please sign in to comment.