Files
bun.sh/test/js/node/test/parallel/util-primordial-monkeypatching.test.js
2024-08-21 23:09:09 -07:00

26 lines
703 B
JavaScript

//#FILE: test-util-primordial-monkeypatching.js
//#SHA1: 72e754f1abd435e598620901f26b087e0bf9d5a7
//-----------------
"use strict";
// Monkeypatch Object.keys() so that it throws an unexpected error. This tests
// that `util.inspect()` is unaffected by monkey-patching `Object`.
const util = require("util");
test("util.inspect() is unaffected by monkey-patching Object.keys()", () => {
const originalObjectKeys = Object.keys;
// Monkey-patch Object.keys
Object.keys = () => {
throw new Error("fhqwhgads");
};
try {
expect(util.inspect({})).toBe("{}");
} finally {
// Restore original Object.keys to avoid affecting other tests
Object.keys = originalObjectKeys;
}
});