Skip to content

Commit 5240e99

Browse files
hasumikinclaude
andcommitted
Add negative assertions and selector_count to DOMTest
Component tests keep needing to assert that something is NOT on the page (a closed panel, a cleared list), and until now every consuming app hand-rolled querySelectorAll counting through JS.eval. DOMTest gains assert_no_selector / assert_no_text as the natural counterparts of the existing assertions, plus selector_count for cardinality checks. Verified against the tsunematsu app's picotest suite (76 tests). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 51ebffb commit 5240e99

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

lib/funicular/testing/node_runner.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ module Funicular
105105
report(!actual.nil?, "Expected selector #{selector.inspect} to exist", selector, actual)
106106
end
107107
108+
def assert_no_selector(selector)
109+
actual = query(selector)
110+
report(actual.nil?, "Expected selector #{selector.inspect} to be absent", selector, actual)
111+
end
112+
113+
def selector_count(selector)
114+
JS.eval("document.querySelectorAll(" + JSON.generate(selector) + ").length").to_i
115+
end
116+
108117
def text(selector = nil)
109118
target = selector ? query(selector) : document.body
110119
target ? target[:textContent].to_s : ''
@@ -120,6 +129,16 @@ module Funicular
120129
)
121130
end
122131
132+
def assert_no_text(expected, selector = nil)
133+
actual = text(selector)
134+
report(
135+
!actual.include?(expected.to_s),
136+
"Expected text not to include #{expected.to_s.inspect}",
137+
expected.to_s,
138+
actual
139+
)
140+
end
141+
123142
def dispatch(selector, event_type)
124143
script = "document.querySelector(" + JSON.generate(selector) + ")" \
125144
+ ".dispatchEvent(new Event(" + JSON.generate(event_type) \

0 commit comments

Comments
 (0)