Skip to content

Add is() and isNot() element identity assertions#2215

Open
NullVoxPopuli-ai-agent wants to merge 1 commit into
mainmatter:masterfrom
NullVoxPopuli-ai-agent:is-element-assertion
Open

Add is() and isNot() element identity assertions#2215
NullVoxPopuli-ai-agent wants to merge 1 commit into
mainmatter:masterfrom
NullVoxPopuli-ai-agent:is-element-assertion

Conversation

@NullVoxPopuli-ai-agent

Copy link
Copy Markdown

Implements #2214.

Adds two new assertions for comparing the target element against another element by reference, while using qunit-dom's element serialization for readable failure messages:

assert.dom('#title').is(element);
assert.dom(el).isNot(otherEl);

Previously the only way to assert that two elements are the same node was assert.strictEqual(el, otherEl), which produces useless failure output for DOM nodes, or piecewise hasAttribute()/hasClass()/hasText() assertions that can't establish identity at all.

Details:

  • is(expected) / isNot(unexpected) compare by reference (===); the failure message serializes both elements (e.g. Element #title is the same element as h2#subtitle with actual: h1#title, expected: h2#subtitle).
  • When two different elements serialize identically, is() annotates the actual value with (a different element with the same description) so the failure isn't a confusing x !== x diff.
  • Both throw a TypeError when passed a non-Element, matching the existing conventions for JavaScript users.
  • Unit tests cover selector and element targets, missing targets, identical-serialization failures, invalid arguments, and chaining. API.md regenerated with pnpm docs (the link-reference renumbering accounts for most of the diff there).

🤖 Generated with Claude Code

Implements the request from mainmatter#2214: assert that the target element is
(or is not) the same element as another one, with failure messages that
use qunit-dom's element serialization instead of the unhelpful output
of `assert.strictEqual(el, otherEl)`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants