This isn't comprehensive but it should be broad enough to ensure that most people who would be affected by blocking monkey patching see a warning. Covers the jasmine namespace as well as classes that are monkey patched by zone.js. Replacing globals (describe/it/etc) doesn't trigger a warning because they belong to the user and are expected to be replaced.
23 lines
637 B
JavaScript
23 lines
637 B
JavaScript
getJasmineRequireObj().deprecateMonkeyPatching = function(j$) {
|
|
return function deprecateMonkeyPatching(obj, keysToSkip) {
|
|
for (const key of Object.keys(obj)) {
|
|
if (!keysToSkip?.includes(key)) {
|
|
let value = obj[key];
|
|
|
|
Object.defineProperty(obj, key, {
|
|
enumerable: key in obj,
|
|
get() {
|
|
return value;
|
|
},
|
|
set(newValue) {
|
|
j$.getEnv().deprecated(
|
|
'Monkey patching detected. This is not supported and will break in a future jasmine-core release.'
|
|
);
|
|
value = newValue;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
};
|