summaryrefslogtreecommitdiff
path: root/test/dompa
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2026-01-10 15:26:52 +0200
committerAsko Nõmm <asko@nmm.ee>2026-01-10 15:26:52 +0200
commit3d18750f03a50e87816cfa234f866cf4cc8f05e9 (patch)
tree440f3160ff09be973dd169b01f2d56bdfc717e6e /test/dompa
parent0863ef2e5c63f081375098c3c06c4ea21cf49e91 (diff)
Fix HTML rendering to handle nil values without removing sibling elements; add tests for nil handling in node hierarchy (#15)
Diffstat (limited to 'test/dompa')
-rw-r--r--test/dompa/nodes_test.cljc38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/dompa/nodes_test.cljc b/test/dompa/nodes_test.cljc
index b1c7b0f..da9b7db 100644
--- a/test/dompa/nodes_test.cljc
+++ b/test/dompa/nodes_test.cljc
@@ -130,6 +130,44 @@
($ x))
["l" "d"])])]))))))
+(deftest nil-in-hierarchy-does-not-remove-siblings-test
+ (testing "nil in a fragment should not remove sibling elements"
+ (is (= "<div>one</div><div>two</div>"
+ (nodes/->html
+ [($ :<>
+ ($ :div "one")
+ ($ :div "two")
+ nil)]))))
+
+ (testing "nil between siblings should not affect them"
+ (is (= "<div>one</div><div>two</div>"
+ (nodes/->html
+ [($ :<>
+ ($ :div "one")
+ nil
+ ($ :div "two"))]))))
+
+ (testing "multiple nils should not affect siblings"
+ (is (= "<div>one</div><div>two</div><div>three</div>"
+ (nodes/->html
+ [($ :<>
+ nil
+ ($ :div "one")
+ nil
+ ($ :div "two")
+ nil
+ ($ :div "three")
+ nil)]))))
+
+ (testing "nil inside nested element should not affect parent siblings"
+ (is (= "<div><span>hello</span></div><div>world</div>"
+ (nodes/->html
+ [($ :<>
+ ($ :div
+ ($ :span "hello")
+ nil)
+ ($ :div "world"))])))))
+
(deftest traverse-test
(let [traverser-fn (fn [node]
(if (= :dompa/text (:node/name node))