test: add tests for utils helper
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 8 May 2023 20:31:36 +0000 (22:31 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 8 May 2023 20:31:36 +0000 (22:31 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/utils.test.js [new file with mode: 0644]

diff --git a/tests/utils.test.js b/tests/utils.test.js
new file mode 100644 (file)
index 0000000..7d4040c
--- /dev/null
@@ -0,0 +1,46 @@
+const { expect } = require('expect')
+const { isPlainObject, median } = require('../lib/utils')
+
+describe('Utils test suite', () => {
+  it('Verify median computation', () => {
+    const array = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03]
+    expect(median(array)).toBe(2.535)
+  })
+
+  it('Verify isPlainObject() behavior', () => {
+    expect(isPlainObject(null)).toBe(false)
+    expect(isPlainObject(undefined)).toBe(false)
+    expect(isPlainObject(true)).toBe(false)
+    expect(isPlainObject(false)).toBe(false)
+    expect(isPlainObject(0)).toBe(false)
+    expect(isPlainObject('')).toBe(false)
+    expect(isPlainObject([])).toBe(false)
+    expect(isPlainObject(() => {})).toBe(false)
+    expect(isPlainObject(new Date())).toBe(false)
+    expect(isPlainObject(new RegExp())).toBe(false)
+    expect(isPlainObject(new Error())).toBe(false)
+    expect(isPlainObject(new Map())).toBe(false)
+    expect(isPlainObject(new Set())).toBe(false)
+    expect(isPlainObject(new WeakMap())).toBe(false)
+    expect(isPlainObject(new WeakSet())).toBe(false)
+    expect(isPlainObject(new Int8Array())).toBe(false)
+    expect(isPlainObject(new Uint8Array())).toBe(false)
+    expect(isPlainObject(new Uint8ClampedArray())).toBe(false)
+    expect(isPlainObject(new Int16Array())).toBe(false)
+    expect(isPlainObject(new Uint16Array())).toBe(false)
+    expect(isPlainObject(new Int32Array())).toBe(false)
+    expect(isPlainObject(new Uint32Array())).toBe(false)
+    expect(isPlainObject(new Float32Array())).toBe(false)
+    expect(isPlainObject(new Float64Array())).toBe(false)
+    expect(isPlainObject(new BigInt64Array())).toBe(false)
+    expect(isPlainObject(new BigUint64Array())).toBe(false)
+    expect(isPlainObject(new Promise(() => {}))).toBe(false)
+    expect(isPlainObject(new WeakRef({}))).toBe(false)
+    expect(isPlainObject(new FinalizationRegistry(() => {}))).toBe(false)
+    expect(isPlainObject(new ArrayBuffer())).toBe(false)
+    expect(isPlainObject(new SharedArrayBuffer())).toBe(false)
+    expect(isPlainObject(new DataView(new ArrayBuffer()))).toBe(false)
+    expect(isPlainObject({})).toBe(true)
+    expect(isPlainObject({ a: 1 })).toBe(true)
+  })
+})