dominator_testing/
lib.rs

1pub mod barrier_testing;
2pub mod conversion;
3pub mod element_utilities;
4
5use dominator::{body, Dom};
6use thiserror::Error;
7use wasm_bindgen::{JsCast, JsValue};
8use wasm_bindgen_futures::JsFuture;
9
10pub mod prelude {
11    pub use super::mount_test_dom;
12    pub use super::async_yield;
13    pub use super::barrier_testing::*;
14    pub use super::element_utilities::*;
15    pub use super::conversion::*;
16}
17
18/// Attaches the provided dom node to the browser body node, replacing the previous children.
19/// Replacing is important to avoid bleeding between tests
20pub fn mount_test_dom(dom: Dom) {
21    dominator::replace_dom(
22        &body(),
23        &body().first_child().unwrap(),
24        dom,
25    );
26}
27
28/// Utility for yielding time back to the browser.
29/// This is necessary because of the single threaded nature of the browser environment
30pub async fn async_yield() {
31    JsFuture::from(js_sys::Promise::resolve(&JsValue::null()))
32        .await
33        .unwrap();
34}
35
36#[derive(Error, Debug)]
37pub enum DominatorTestingError {
38    #[error("Timeout error waiting for {0}")]
39    BarrierTimeOut(String),
40}
41