Skip to content

Instantly share code, notes, and snippets.

@njam
Created February 5, 2020 19:21
Show Gist options
  • Save njam/13d53f2173d73d30398cd80c4a321091 to your computer and use it in GitHub Desktop.
Save njam/13d53f2173d73d30398cd80c4a321091 to your computer and use it in GitHub Desktop.
Rendering rust-dominator app in headless browser with wasm-bindgen-test
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use wasm_bindgen_test::wasm_bindgen_test_configure;
use dominator_test::App;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test(async)]
async fn test_html() {
let html: String = render_app().await;
assert_eq!(html, "...");
}
#[wasm_bindgen]
pub async fn render_app() -> String {
let document = web_sys::window().unwrap().document().unwrap();
let mount_el = document.create_element("div").unwrap();
let app = App::default();
dominator::append_dom(&mount_el, app.render());
gloo_timers::future::TimeoutFuture::new(0).await;
mount_el.inner_html()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment