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 aa705b8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/yew/src/dom_bundle/btag/mod.rs
Expand Up @@ -931,6 +931,48 @@ 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

1 comment on commit aa705b8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Yew master branch benchmarks (Lower is better)'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: aa705b8 Previous: 3159424 Ratio
yew-struct-keyed 06_remove-one-1k 57.31699999999999 26.724 2.14

This comment was automatically generated by workflow using github-action-benchmark.

CC: @yewstack/yew

Please sign in to comment.