From: Jérôme Benoit Date: Tue, 30 Jan 2024 17:28:14 +0000 (+0100) Subject: test: improve isAsyncFunction() test X-Git-Tag: v3.1.20~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f903b9c3bee3649a69e13c1259270fd9730979c7;p=poolifier.git test: improve isAsyncFunction() test Signed-off-by: Jérôme Benoit --- 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', () => {