Created
February 5, 2020 19:21
-
-
Save njam/13d53f2173d73d30398cd80c4a321091 to your computer and use it in GitHub Desktop.
Rendering rust-dominator app in headless browser with wasm-bindgen-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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