From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../puppeteer-core/src/util/decorators.test.ts | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 remote/test/puppeteer/packages/puppeteer-core/src/util/decorators.test.ts (limited to 'remote/test/puppeteer/packages/puppeteer-core/src/util/decorators.test.ts') diff --git a/remote/test/puppeteer/packages/puppeteer-core/src/util/decorators.test.ts b/remote/test/puppeteer/packages/puppeteer-core/src/util/decorators.test.ts new file mode 100644 index 0000000000..4cdaf15d5b --- /dev/null +++ b/remote/test/puppeteer/packages/puppeteer-core/src/util/decorators.test.ts @@ -0,0 +1,79 @@ +/** + * @license + * Copyright 2023 Google Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import {describe, it} from 'node:test'; + +import expect from 'expect'; +import sinon from 'sinon'; + +import {invokeAtMostOnceForArguments} from './decorators.js'; + +describe('decorators', function () { + describe('invokeAtMostOnceForArguments', () => { + it('should delegate calls', () => { + const spy = sinon.spy(); + class Test { + @invokeAtMostOnceForArguments + test(obj1: object, obj2: object) { + spy(obj1, obj2); + } + } + const t = new Test(); + expect(spy.callCount).toBe(0); + const obj1 = {}; + const obj2 = {}; + t.test(obj1, obj2); + expect(spy.callCount).toBe(1); + }); + + it('should prevent repeated calls', () => { + const spy = sinon.spy(); + class Test { + @invokeAtMostOnceForArguments + test(obj1: object, obj2: object) { + spy(obj1, obj2); + } + } + const t = new Test(); + expect(spy.callCount).toBe(0); + const obj1 = {}; + const obj2 = {}; + t.test(obj1, obj2); + expect(spy.callCount).toBe(1); + expect(spy.lastCall.calledWith(obj1, obj2)).toBeTruthy(); + t.test(obj1, obj2); + expect(spy.callCount).toBe(1); + expect(spy.lastCall.calledWith(obj1, obj2)).toBeTruthy(); + const obj3 = {}; + t.test(obj1, obj3); + expect(spy.callCount).toBe(2); + expect(spy.lastCall.calledWith(obj1, obj3)).toBeTruthy(); + }); + + it('should throw an error for dynamic argumetns', () => { + class Test { + @invokeAtMostOnceForArguments + test(..._args: unknown[]) {} + } + const t = new Test(); + t.test({}); + expect(() => { + t.test({}, {}); + }).toThrow(); + }); + + it('should throw an error for non object arguments', () => { + class Test { + @invokeAtMostOnceForArguments + test(..._args: unknown[]) {} + } + const t = new Test(); + expect(() => { + t.test(1); + }).toThrow(); + }); + }); +}); -- cgit v1.2.3