From 78a7614ed5c9bfc8088a71de6b4c8a0a0345f59f Mon Sep 17 00:00:00 2001 From: Mykola Humanov Date: Mon, 30 Dec 2024 10:18:17 +0200 Subject: [PATCH] src/node/node_ref.rs: update --- src/node/node_ref.rs | 2 +- tests/node-traversal.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/node/node_ref.rs b/src/node/node_ref.rs index d776f58..5ee3d08 100644 --- a/src/node/node_ref.rs +++ b/src/node/node_ref.rs @@ -645,7 +645,7 @@ impl NodeRef<'_> { /// Checks if the node matches the given matcher pub fn is_match(&self, matcher: &Matcher) -> bool { - matcher.match_element(self) + self.is_element() && matcher.match_element(self) } /// Checks if the node matches the given selector diff --git a/tests/node-traversal.rs b/tests/node-traversal.rs index 498547a..67326d5 100644 --- a/tests/node-traversal.rs +++ b/tests/node-traversal.rs @@ -231,4 +231,18 @@ fn test_node_is() { let parent_node = parent_sel.nodes().first().unwrap(); assert!(parent_node.is("div#parent")); assert!(parent_node.is(":has(#first-child)")); +} + + +#[cfg_attr(not(target_arch = "wasm32"), test)] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn test_text_node_is() { + let doc = Document::from(ANCESTORS_CONTENTS); + + let sel = doc.select_single("#first-child"); + let node = sel.nodes().first().unwrap(); + let first_child = node.first_child().unwrap(); + assert!(first_child.is_text()); + + assert!(!first_child.is("#text")); } \ No newline at end of file