Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/node/node_ref.rs: update #54

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
Loading