mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
732e505018
We keep getting PRs that target single usages of `hasOwnProperty` and we have ~100 of them. These changes aim to address the issue centrally by swapping out all the instances and adding a lint rule against introducing new ones.
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
import domino from '../../third_party/domino/bundled-domino';
|
|
import {applyShims} from '../src/shims';
|
|
|
|
describe('applyShims()', () => {
|
|
const globalClone = {...global};
|
|
|
|
afterEach(() => {
|
|
// Un-patch `global`.
|
|
const currentProps = Object.keys(global);
|
|
for (const prop of currentProps) {
|
|
if (['navigator', 'crypto'].includes(prop)) {
|
|
// These props are just a getter and cannot be changed
|
|
continue;
|
|
}
|
|
if (Object.hasOwn(globalClone, prop)) {
|
|
(global as any)[prop] = (globalClone as any)[prop];
|
|
} else {
|
|
delete (global as any)[prop];
|
|
}
|
|
}
|
|
});
|
|
|
|
it('should load `domino.impl` onto `global`', () => {
|
|
expect(global).not.toEqual(jasmine.objectContaining(domino.impl));
|
|
|
|
applyShims();
|
|
expect(global).toEqual(jasmine.objectContaining(domino.impl));
|
|
});
|
|
|
|
it('should define `KeyboardEvent` on `global`', () => {
|
|
expect((global as any).KeyboardEvent).not.toBe((domino.impl as any).Event);
|
|
|
|
applyShims();
|
|
expect((global as any).KeyboardEvent).toBe((domino.impl as any).Event);
|
|
});
|
|
});
|