-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils-test.mjs
30 lines (24 loc) · 871 Bytes
/
utils-test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getCallerDetails } from './utils-debug.mjs'
import { L } from './utils-debug.mjs'
import { objectDeepEqual } from './utils-object.mjs'
/**@type {boolean}*/const gTest = true// true = run tests, false = don't run tests
/**
* If fn evaluates to false, msg is output to the console.
*
* @param {function} fn - require a function input so we can choose to not evaluate them if testing is turned off
* @param {any} expectedResult
* @returns
*/
export function assertEquals(fn, expectedResult) {
if (false === gTest) return
const l = fn()
const r = expectedResult
const ls = JSON.stringify(l,null,2)
const rs = JSON.stringify(r,null,2)
const d = getCallerDetails()
L()
L(d)
L('assertEquals() computed:'+ls)
L('assertEquals() expected:'+rs)
if (!objectDeepEqual(l,r)) throw new Error(`${d}\nactual--> ${ls} !== ${rs} <--expected`)
}