Skip to content

Commit

Permalink
Merge pull request #54 from niklak/fix/node-is
Browse files Browse the repository at this point in the history
src/node/node_ref.rs: update
  • Loading branch information
niklak authored Dec 30, 2024
2 parents 180d641 + 78a7614 commit 41cfa46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node/node_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/node-traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

0 comments on commit 41cfa46

Please sign in to comment.