on master help sign in
Add tests for changing namespace
commit848215b540bd6d809304cc77f10cdf0d10d52708 authorRyan Levick <ryan.levick@gmail.com> dateWed 20 Mar 2019, 23:50 (8 years ago) parentc2cb76c
4 files changed+25−4
src/node.rs+5 src/vdom.rs+4−4 tests/web/main.rs+3 tests/web/render.rs+13
src/node.rs+5
@@ -174,6 +174,11 @@ impl<'a> ElementNode<'a> {
174174 pub fn children(&self) -> &'a [Node<'a>] {
175175 self.children
176176 }
177+
178+ /// Get this element's namespace.
179+ pub fn namespace(&self) -> Option<&'a str> {
180+ self.namespace
181+ }
177182}
178183
179184union CallbackFatPtr<'a> {
src/vdom.rs+4−4
@@ -303,19 +303,19 @@ impl VdomInnerExclusive {
303303 listeners: new_listeners,
304304 attributes: new_attributes,
305305 children: new_children,
306− namespace: _,
306+ namespace: new_namespace,
307307 }),
308308 Node::Element(ElementNode {
309309 tag_name: old_tag_name,
310310 listeners: old_listeners,
311311 attributes: old_attributes,
312312 children: old_children,
313− namespace: _,
313+ namespace: old_namespace,
314314 }),
315315 ) => {
316316 debug!(" updating an element");
317− if new_tag_name != old_tag_name {
318− debug!(" different tag names; creating new element and replacing old element");
317+ if new_tag_name != old_tag_name || new_namespace != old_namespace {
318+ debug!(" different tag names or namespaces; creating new element and replacing old element");
319319 self.create(registry, new);
320320 self.change_list.emit_replace_with();
321321 return;
tests/web/main.rs+3
@@ -92,6 +92,9 @@ pub fn assert_rendered<R: Render>(container: &web_sys::Element, r: &R) {
9292 .expect("`actual` should be an `Element`");
9393 check_attributes(actual.attributes(), elem.attributes());
9494 check_children(actual.child_nodes(), elem.children());
95+ if let Some(namespace) = elem.namespace() {
96+ assert_eq!(actual.namespace_uri(), Some(namespace.into()))
97+ }
9598 }
9699 }
97100 }
tests/web/render.rs+13
@@ -240,4 +240,17 @@ before_after! {
240240 .finish()
241241 }
242242 }
243+
244+ same_tag_different_namespace {
245+ before(bump) {
246+ div(bump)
247+ .namespace(Some("http://example.com"))
248+ .finish()
249+ }
250+ after(bump) {
251+ div(bump)
252+ .namespace(Some("http://example.net"))
253+ .finish()
254+ }
255+ }
243256}