mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
A failed assert.equal or deepEqual prints both operands, and a happy-dom node reaches the whole page and window: printing one exhausted memory and took the machine down. assertSameNode() compares identity and fails with a short description of each node; every node comparison in the happy-dom tests uses it.
20 lines
627 B
JavaScript
20 lines
627 B
JavaScript
import assert from 'node:assert/strict';
|
|
|
|
const describe = (node) =>
|
|
node?.nodeType === 1
|
|
? `<${node.tagName.toLowerCase()}${node.id ? `#${node.id}` : ''}>`
|
|
: String(node);
|
|
|
|
/**
|
|
* Assert that two DOM nodes (or a node and null) are the same. Never hand
|
|
* happy-dom nodes to assert.equal or deepEqual: a failure prints both, and a
|
|
* node reaches the whole page and window, which runs the process out of
|
|
* memory.
|
|
*/
|
|
export function assertSameNode(actual, expected, message = '') {
|
|
assert.ok(
|
|
actual === expected,
|
|
`${message ? `${message}: ` : ''}${describe(actual)} is not ${describe(expected)}`,
|
|
);
|
|
}
|