MCPcopy Index your code
hub / github.com/angular/angular / setupFakePolyfill

Function setupFakePolyfill

packages/zone.js/test/test_fake_polyfill.ts:14–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12
13const global: any = globalThis;
14export function setupFakePolyfill(): void {
15 // add custom properties to Native Error
16 const NativeError = global['Error'];
17 NativeError.customProperty = 'customProperty';
18 NativeError.customFunction = function () {};
19
20 // Polyfill Promise.try for testing pass-through
21 if (global.Promise && typeof global.Promise.try !== 'function') {
22 global.Promise.try = function (callback: any) {
23 return new global.Promise((resolve: any, reject: any) => {
24 try {
25 resolve(callback());
26 } catch (e) {
27 reject(e);
28 }
29 });
30 };
31 }
32
33 // add fake cordova polyfill for test
34 const fakeCordova = function () {};
35
36 (fakeCordova as any).exec = function (
37 success: Function,
38 error: Function,
39 service: string,
40 action: string,
41 args: any[],
42 ) {
43 if (action === 'successAction') {
44 success();
45 } else {
46 error();
47 }
48 };
49
50 global.cordova = fakeCordova;
51
52 const TestTarget = (global.TestTarget = function () {});
53
54 Object.defineProperties(TestTarget.prototype, {
55 'onprop1': {configurable: true, writable: true},
56 'onprop2': {configurable: true, writable: true},
57 'onprop3': {
58 configurable: true,
59 get: function () {
60 return this._onprop3;
61 },
62 set: function (_value) {
63 this._onprop3 = _value;
64 },
65 },
66 '_onprop3': {configurable: true, writable: true, value: function () {}},
67 'addEventListener': {
68 configurable: true,
69 writable: true,
70 value: function (eventName: string, callback: Function) {
71 if (!this.events) {

Calls 5

rejectFunction · 0.85
runMethod · 0.65
resolveFunction · 0.50
callbackFunction · 0.50
errorFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…