-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,4 @@ features = [ | |
|
||
[dev-dependencies] | ||
log = "0.4.8" | ||
wasm-bindgen-test = "0.3.14" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(dead_code)] | ||
|
||
pub fn obtain_result() -> String { | ||
gloo::utils::document() | ||
.get_element_by_id("result") | ||
.expect("No result found. Most likely, the application crashed and burned") | ||
.inner_html() | ||
} | ||
|
||
pub fn obtain_result_by_id(id: &str) -> String { | ||
gloo::utils::document() | ||
.get_element_by_id(id) | ||
.expect("No result found. Most likely, the application crashed and burned") | ||
.inner_html() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::time::Duration; | ||
use wasm_bindgen_test::*; | ||
use yew::platform::time::sleep; | ||
use yew::prelude::*; | ||
|
||
mod common; | ||
|
||
use common::obtain_result; | ||
|
||
wasm_bindgen_test_configure!(run_in_browser); | ||
|
||
use yew_hooks::use_counter; | ||
|
||
#[wasm_bindgen_test] | ||
async fn use_counter_works() { | ||
#[function_component] | ||
fn TestComponent() -> Html { | ||
let counter = use_counter(0); | ||
if *counter < 5 { | ||
counter.increase(); | ||
} | ||
html! { | ||
<div> | ||
{"Test Output: "} | ||
<div id="result">{*counter}</div> | ||
{"\n"} | ||
</div> | ||
} | ||
} | ||
|
||
yew::Renderer::<TestComponent>::with_root( | ||
gloo::utils::document().get_element_by_id("output").unwrap(), | ||
) | ||
.render(); | ||
sleep(Duration::ZERO).await; | ||
let result = obtain_result(); | ||
assert_eq!(result.as_str(), "5"); | ||
} |