From ae034d83607f4635829d5ff1ff307eb633dbda68 Mon Sep 17 00:00:00 2001 From: Material Web Team Date: Tue, 19 Jul 2022 13:32:40 -0700 Subject: [PATCH] chore: remove spyOnAllFunctions PiperOrigin-RevId: 461960797 --- testing/jasmine.ts | 68 ---------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 testing/jasmine.ts diff --git a/testing/jasmine.ts b/testing/jasmine.ts deleted file mode 100644 index 0886e356c..000000000 --- a/testing/jasmine.ts +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @license - * Copyright 2021 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import 'jasmine'; - -/** - * SpyObj with "and" for chaining a group of spies. - */ -export type SpyGroup = jasmine.SpyObj&{ - and: SpyGroupAnd; -}; - -/** - * SpyAnd for group of multiple spies. - */ -export interface SpyGroupAnd { - callThrough(): jasmine.SpyObj; - stub(): jasmine.SpyObj; -} - -/** - * A more versatile `spyOnAllFunctions()` that allows chaining `callThrough()` - * and `stub()` for all function spies. - * - * Spies on all functions, including those from the prototype chain (useful for - * class instance objects). - * - * @param obj The object to spy on all functions. - * @return The spied object. - */ -export function spyOnAllFunctions(obj: T) { - const functionKeys = new Set(); - let target: object|null = obj; - while (target) { - const keys = - Object.getOwnPropertyNames(target) as Array; - for (const key of keys) { - if (target.hasOwnProperty(key) && typeof target[key] === 'function') { - functionKeys.add(key); - } - } - target = Object.getPrototypeOf(target); - } - for (const key of functionKeys) { - spyOn(obj, key); - } - - const spyObj = obj as SpyGroup; - spyObj.and = { - callThrough() { - for (const key of functionKeys) { - (spyObj[key] as jasmine.Spy).and.callThrough(); - } - return spyObj; - }, - stub() { - for (const key of functionKeys) { - (spyObj[key] as jasmine.Spy).and.stub(); - } - return spyObj; - }, - }; - - return spyObj; -}