Clone in a terminal:
Commit 84a11d8
Johan Mattsson - 2026-07-12T20:22:50+00:00
84a11d845cd137a174e4e5e402f48283eb375dcfjohan.mattsson.m@gmail.com

Attribute tests

Changed files (4)

Diff

diff --git a/src/lib.rs b/src/lib.rsindex 8671c0e..2fb53e5 100644--- a/src/lib.rs+++ b/src/lib.rs@@ -301,6 +301,7 @@ pub fn get_cookie_value(name: &str) -> Option<String> {             }         }     }+     None } diff --git a/test.sh b/test.shindex ccdeb6a..a61c060 100755--- a/test.sh+++ b/test.sh@@ -1,4 +1,4 @@ #!/bin/bash set -e -wasm-pack test --chrome+wasm-pack test --chrome --test alltestsdiff --git a/tests/component.rs b/tests/component.rsindex e4acd05..fd50f0b 100644--- a/tests/component.rs+++ b/tests/component.rs@@ -3,8 +3,6 @@ use kaja_web_component::component; use wasm_bindgen_test::*; use web_sys::HtmlElement; -wasm_bindgen_test_configure!(run_in_browser);- fn setup_test() {     let window = web_sys::window().unwrap();     let document = window.document().unwrap();@@ -44,6 +42,7 @@ fn test_component() {     let test_component = component.borrow();     assert!(test_component.tested); }+ #[wasm_bindgen_test] fn test_custom_id() {     setup_test();@@ -62,9 +61,45 @@ fn test_custom_id() {     assert!(test_component.tested); } +#[wasm_bindgen_test]+fn test_attribute_updated() {+    setup_test();++    let content = html! {{+        <test-component1 id="custom-id" test-attribute="initial-value"></test-component1>+    }};++    try_inner_html("#test-div", &content);++    let element = get_element("test-component1").unwrap();++    {+        let component = TestComponent1::get_component("custom-id").unwrap();+        let test_component = component.borrow();++        assert!(test_component.tested);+        assert!(test_component.attribute_updated);+        assert_eq!(test_component.test_attribute, "initial-value"); // value on struct not on element+    }++    element+        .set_attribute("test-attribute", "updated-value")+        .unwrap();++    {+        let component = TestComponent1::get_component("custom-id").unwrap();+        let test_component = component.borrow();++        assert_eq!(test_component.test_attribute, "updated-value");+        assert!(test_component.attribute_updated);+    }+}+ #[component("test-component1")] struct TestComponent1 {     tested: bool,+    attribute_updated: bool,+    test_attribute: String, }  impl Component for TestComponent1 {@@ -73,4 +108,22 @@ impl Component for TestComponent1 {         let mut test_component = component.borrow_mut();         test_component.tested = true;     }++    fn observed_attributes() -> &'static [&'static str] {+        &["test-attribute"]+    }++    fn attribute_changed(id: &str, name: &str, _old_value: &str, new_value: &str) {+        log!(+            "running attribute_changed for ",+            name,+            " new_value: ",+            new_value+        );++        let component = TestComponent1::get_component(id).unwrap();+        let mut test_component = component.borrow_mut();+        test_component.attribute_updated = true;+        test_component.test_attribute = new_value.to_string();+    } }diff --git a/tests/dom.rs b/tests/dom.rsdeleted file mode 100644index 25fcfea..0000000--- a/tests/dom.rs+++ /dev/null@@ -1,10 +0,0 @@-use wasm_bindgen_test::*;--wasm_bindgen_test_configure!(run_in_browser);--#[wasm_bindgen_test]-fn test_dom() {-    let window = web_sys::window().unwrap();-    let document = window.document().unwrap();-    assert!(document.body().is_some());-}

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112