Skip to content

Commit

Permalink
add test case for test for bug #2653
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerdietmar committed May 4, 2022
1 parent 9a04692 commit 3b54e46
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/yew/src/dom_bundle/btag/mod.rs
Expand Up @@ -931,6 +931,49 @@ mod tests {
"<div id=\"after\"></div>"
);
}

// test for bug: https://github.com/yewstack/yew/pull/2653
#[test]
fn test_index_map_attribute_diff() {
let (root, scope, parent) = setup_parent();

let test_ref = NodeRef::default();

// We want to test appy_diff with Attributes::IndexMap, so we
// need to create the VTag manually

// Create <div disabled="disabled" tabindex="0">
let mut vtag = VTag::new("div");
vtag.node_ref = test_ref.clone();
vtag.add_attribute("disabled", "disabled");
vtag.add_attribute("tabindex", "0");

let elem = VNode::VTag(Box::new(vtag));

let (_, mut elem) = elem.attach(&root, &scope, &parent, NodeRef::default());

// Create <div tabindex="0"> (removed first attribute "disabled")
let mut vtag = VTag::new("div");
vtag.node_ref = test_ref.clone();
vtag.add_attribute("tabindex", "0");
let next_elem = VNode::VTag(Box::new(vtag));
let elem_vtag = assert_vtag(next_elem);


// Sync happens here
// this should remove the the "disabled" attribute
elem_vtag.reconcile_node(&root, &scope, &parent, NodeRef::default(), &mut elem);

assert_eq!(
test_ref
.get()
.unwrap()
.dyn_ref::<web_sys::Element>()
.unwrap()
.outer_html(),
"<div tabindex=\"0\"></div>"
)
}
}

#[cfg(all(test, feature = "wasm_test"))]
Expand Down

0 comments on commit 3b54e46

Please sign in to comment.