mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
test: compare DOM nodes by identity, never through assert.equal
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.
This commit is contained in:
1 parent
e949584c0a
commit
3a2acf9b0f
8 files changed
+46
-20
No files matched your search
@@ -0,0 +1,19 @@
|
||||
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)}`,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user