From aba955e18c656962a79c88816371be2180bbf268 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 8 May 2023 22:31:36 +0200 Subject: [PATCH] test: add tests for utils helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/utils.test.js | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/utils.test.js diff --git a/tests/utils.test.js b/tests/utils.test.js new file mode 100644 index 000000000..7d4040ce3 --- /dev/null +++ b/tests/utils.test.js @@ -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) + }) +}) -- 2.43.0