Skip to content

Commit

Permalink
Add query helpers test
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Aug 18, 2024
1 parent 5be7ad8 commit 2ee2be7
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/dom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ web-sys = { workspace = true, features = [

[dev-dependencies]
wasm-bindgen-test.workspace = true
mockall = "0.13.0"
1 change: 1 addition & 0 deletions packages/dom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod types;
mod util;

pub use config::{configure, get_config};
pub use error::QueryError;
pub use get_node_text::*;
pub use get_queries_for_element::*;
pub use matches::get_default_normalizer;
Expand Down
41 changes: 41 additions & 0 deletions packages/dom/tests/query_helpers.rs
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
use std::sync::Arc;

use mockall::automock;
use testing_library_dom::{
configure, get_element_error, ConfigFnOrPartial, PartialConfig, QueryError,
};
use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure};
use web_sys::{Document, Element};

wasm_bindgen_test_configure!(run_in_browser);

#[automock]
trait GetElementError {
fn get_element_error(message: Option<String>, container: Element) -> QueryError;
}

#[wasm_bindgen_test]
fn should_delegate_to_config_get_element_error() {
let message = Some("test Message".to_string());
let container = Document::new()
.expect("Document should be created.")
.create_element("div")
.expect("Element should be created");

let mock = MockGetElementError::get_element_error_context();
mock.expect()
.withf_st({
let message = message.clone();
let container = container.clone();

move |m, c| *m == message && *c == container
})
.returning(|_, _| QueryError::Element("".into()));

configure(ConfigFnOrPartial::Partial(
PartialConfig::default().get_element_error(Arc::new(|message, container| {
MockGetElementError::get_element_error(message, container)
})),
));

get_element_error(message, container);
}

0 comments on commit 2ee2be7

Please sign in to comment.