Add empty_changed_in_front test
@@ -919,8 +919,49 @@ pub mod tests {
assert_eq!(child3.get_attribute("class"), Some("second".to_string()));
}
- /// Test that if a seed::empty() is changed to a non-empty El, then the new element is
- /// inserted at the correct position.
+ /// Test that if the first child was a seed::empty() and it is changed to a non-empty El,
+ /// then the new element is inserted at the correct position.
+ #[wasm_bindgen_test]
+ fn empty_changed_in_front() {
+ let mailbox = Mailbox::new(|_msg: Msg| {});
+
+ let doc = util::document();
+ let parent = doc.create_element("div").unwrap();
+
+ let mut vdom = make_vdom(&doc, El::empty(seed::dom_types::Tag::Div));
+ // clone so we can keep using it after vdom is modified
+ let old_ws = vdom.el_ws.as_ref().unwrap().clone();
+ parent.append_child(&old_ws).unwrap();
+
+ assert_eq!(parent.children().length(), 1);
+ assert_eq!(old_ws.child_nodes().length(), 0);
+
+ vdom = setup_and_patch(&doc, &parent, &mailbox, vdom, div![seed::empty(), "b", "c"]);
+ assert_eq!(parent.children().length(), 1);
+ assert!(old_ws.is_same_node(parent.first_child().as_ref()));
+ assert_eq!(
+ iter_child_nodes(&old_ws).map(|node| node.text_content().unwrap()).collect::<Vec<_>>(),
+ &["b", "c"],
+ );
+
+ setup_and_patch(
+ &doc,
+ &parent,
+ &mailbox,
+ vdom,
+ div!["a", "b", "c"],
+ );
+
+ assert_eq!(parent.children().length(), 1);
+ assert!(old_ws.is_same_node(parent.first_child().as_ref()));
+ assert_eq!(
+ iter_child_nodes(&old_ws).map(|node| node.text_content().unwrap()).collect::<Vec<_>>(),
+ &["a", "b", "c"],
+ );
+ }
+
+ /// Test that if a middle child was a seed::empty() and it is changed to a non-empty El,
+ /// then the new element is inserted at the correct position.
#[wasm_bindgen_test]
fn empty_changed_in_the_middle() {
let mailbox = Mailbox::new(|_msg: Msg| {});
