test: add test for isAsyncFunction() helper
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Jul 2023 19:01:43 +0000 (21:01 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Jul 2023 19:01:43 +0000 (21:01 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/utils.test.js

index 7ad3a5c7efee2cf217c47f556faa92ca4671229a..f220927edc9cc180ba9740d4e191508194dd40b6 100644 (file)
@@ -1,6 +1,7 @@
 const { expect } = require('expect')
 const {
   availableParallelism,
+  isAsyncFunction,
   isKillBehavior,
   isPlainObject,
   median,
@@ -79,6 +80,49 @@ describe('Utils test suite', () => {
     expect(isKillBehavior(KillBehaviors.SOFT)).toBe(false)
     expect(isKillBehavior(KillBehaviors.HARD)).toBe(false)
     expect(isKillBehavior(KillBehaviors.HARD, null)).toBe(false)
+    expect(isKillBehavior(KillBehaviors.HARD, undefined)).toBe(false)
     expect(isKillBehavior(KillBehaviors.SOFT, 'unknown')).toBe(false)
   })
+
+  it('Verify isAsyncFunction() behavior', () => {
+    expect(isAsyncFunction(null)).toBe(false)
+    expect(isAsyncFunction(undefined)).toBe(false)
+    expect(isAsyncFunction(true)).toBe(false)
+    expect(isAsyncFunction(false)).toBe(false)
+    expect(isAsyncFunction(0)).toBe(false)
+    expect(isAsyncFunction('')).toBe(false)
+    expect(isAsyncFunction([])).toBe(false)
+    expect(isAsyncFunction(new Date())).toBe(false)
+    expect(isAsyncFunction(new RegExp())).toBe(false)
+    expect(isAsyncFunction(new Error())).toBe(false)
+    expect(isAsyncFunction(new Map())).toBe(false)
+    expect(isAsyncFunction(new Set())).toBe(false)
+    expect(isAsyncFunction(new WeakMap())).toBe(false)
+    expect(isAsyncFunction(new WeakSet())).toBe(false)
+    expect(isAsyncFunction(new Int8Array())).toBe(false)
+    expect(isAsyncFunction(new Uint8Array())).toBe(false)
+    expect(isAsyncFunction(new Uint8ClampedArray())).toBe(false)
+    expect(isAsyncFunction(new Int16Array())).toBe(false)
+    expect(isAsyncFunction(new Uint16Array())).toBe(false)
+    expect(isAsyncFunction(new Int32Array())).toBe(false)
+    expect(isAsyncFunction(new Uint32Array())).toBe(false)
+    expect(isAsyncFunction(new Float32Array())).toBe(false)
+    expect(isAsyncFunction(new Float64Array())).toBe(false)
+    expect(isAsyncFunction(new BigInt64Array())).toBe(false)
+    expect(isAsyncFunction(new BigUint64Array())).toBe(false)
+    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({})).toBe(false)
+    expect(isAsyncFunction({ a: 1 })).toBe(false)
+    expect(isAsyncFunction(() => {})).toBe(false)
+    expect(isAsyncFunction(function () {})).toBe(false)
+    expect(isAsyncFunction(function named () {})).toBe(false)
+    expect(isAsyncFunction(async () => {})).toBe(true)
+    expect(isAsyncFunction(async function () {})).toBe(true)
+    expect(isAsyncFunction(async function named () {})).toBe(true)
+  })
 })