From f903b9c3bee3649a69e13c1259270fd9730979c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 30 Jan 2024 18:28:14 +0100 Subject: [PATCH] test: improve isAsyncFunction() test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/utils.test.mjs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/utils.test.mjs b/tests/utils.test.mjs index 1078c1fd..b6551dbd 100644 --- a/tests/utils.test.mjs +++ b/tests/utils.test.mjs @@ -147,7 +147,8 @@ describe('Utils test suite', () => { expect(isAsyncFunction('')).toBe(false) expect(isAsyncFunction([])).toBe(false) expect(isAsyncFunction(new Date())).toBe(false) - expect(isAsyncFunction(new RegExp())).toBe(false) + // eslint-disable-next-line prefer-regex-literals + expect(isAsyncFunction(new RegExp('[a-z]', 'i'))).toBe(false) expect(isAsyncFunction(new Error())).toBe(false) expect(isAsyncFunction(new Map())).toBe(false) expect(isAsyncFunction(new Set())).toBe(false) @@ -167,9 +168,9 @@ describe('Utils test suite', () => { expect(isAsyncFunction(new Promise(() => {}))).toBe(false) expect(isAsyncFunction(new WeakRef({}))).toBe(false) expect(isAsyncFunction(new FinalizationRegistry(() => {}))).toBe(false) - expect(isAsyncFunction(new ArrayBuffer())).toBe(false) - expect(isAsyncFunction(new SharedArrayBuffer())).toBe(false) - expect(isAsyncFunction(new DataView(new ArrayBuffer()))).toBe(false) + expect(isAsyncFunction(new ArrayBuffer(16))).toBe(false) + expect(isAsyncFunction(new SharedArrayBuffer(16))).toBe(false) + expect(isAsyncFunction(new DataView(new ArrayBuffer(16)))).toBe(false) expect(isAsyncFunction({})).toBe(false) expect(isAsyncFunction({ a: 1 })).toBe(false) expect(isAsyncFunction(() => {})).toBe(false) @@ -178,6 +179,21 @@ describe('Utils test suite', () => { expect(isAsyncFunction(async () => {})).toBe(true) expect(isAsyncFunction(async function () {})).toBe(true) expect(isAsyncFunction(async function named () {})).toBe(true) + class TestClass { + testSync () {} + async testAsync () {} + testArrowSync = () => {} + testArrowAsync = async () => {} + static testStaticSync () {} + static async testStaticAsync () {} + } + const testClass = new TestClass() + expect(isAsyncFunction(testClass.testSync)).toBe(false) + expect(isAsyncFunction(testClass.testAsync)).toBe(true) + expect(isAsyncFunction(testClass.testArrowSync)).toBe(false) + expect(isAsyncFunction(testClass.testArrowAsync)).toBe(true) + expect(isAsyncFunction(TestClass.testStaticSync)).toBe(false) + expect(isAsyncFunction(TestClass.testStaticAsync)).toBe(true) }) it('Verify secureRandom() behavior', () => { -- 2.34.1