From 402d6297f48c1942cbe12c760e3afce81fadb2fe Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Mon, 3 Jun 2024 08:16:43 -0400 Subject: [PATCH] fix counters tests --- examples/counters/Cargo.toml | 3 +- examples/counters/src/lib.rs | 3 +- examples/counters/src/main.rs | 4 +- examples/counters/tests/web.rs | 91 ++++++++++++++++------------------ 4 files changed, 46 insertions(+), 55 deletions(-) diff --git a/examples/counters/Cargo.toml b/examples/counters/Cargo.toml index d59b43035..090cd455b 100644 --- a/examples/counters/Cargo.toml +++ b/examples/counters/Cargo.toml @@ -5,11 +5,10 @@ edition = "2021" [dependencies] leptos = { path = "../../leptos", features = ["csr"] } -log = "0.4" -console_log = "1" console_error_panic_hook = "0.1.7" [dev-dependencies] +gloo-timers = { version = "0.3", features = ["futures"] } wasm-bindgen-test = "0.3.0" wasm-bindgen = "0.2" web-sys = "0.3" diff --git a/examples/counters/src/lib.rs b/examples/counters/src/lib.rs index 7074edf0c..e6be7e9c1 100644 --- a/examples/counters/src/lib.rs +++ b/examples/counters/src/lib.rs @@ -1,5 +1,4 @@ -use leptos::prelude::signal::*; -use leptos::prelude::*; +use leptos::prelude::{signal::*, *}; const MANY_COUNTERS: usize = 1000; diff --git a/examples/counters/src/main.rs b/examples/counters/src/main.rs index 7bf20cc9d..858572fe6 100644 --- a/examples/counters/src/main.rs +++ b/examples/counters/src/main.rs @@ -1,8 +1,6 @@ use counters::Counters; -use leptos::prelude::*; fn main() { - _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); - mount_to_body(|| view! { }) + leptos::mount::mount_to_body(Counters) } diff --git a/examples/counters/tests/web.rs b/examples/counters/tests/web.rs index 2efb0245f..07e1af916 100644 --- a/examples/counters/tests/web.rs +++ b/examples/counters/tests/web.rs @@ -3,14 +3,15 @@ use wasm_bindgen_test::*; wasm_bindgen_test_configure!(run_in_browser); use counters::Counters; -use leptos::*; +use gloo_timers::future::TimeoutFuture; +use leptos::prelude::*; use web_sys::HtmlElement; #[wasm_bindgen_test] -fn inc() { - mount_to_body(|| view! { }); +async fn inc() { + mount_to_body(Counters); - let document = leptos::document(); + let document = document(); let div = document.query_selector("div").unwrap().unwrap(); let add_counter = div .first_child() @@ -18,31 +19,33 @@ fn inc() { .dyn_into::() .unwrap(); + assert_eq!( + div.inner_html(), + "

Total: \ + 0 from 0 counters.

    " + ); + // add 3 counters add_counter.click(); add_counter.click(); add_counter.click(); + TimeoutFuture::new(10).await; + // check HTML assert_eq!( div.inner_html(), "

    Total: 0 from 3 counters.

    • 0
    • 0
    • 0
    " + Counters

    Total: \ + 0 from 3 \ + counters.

    • 0
    • 0
    • 0
    " ); let counters = div @@ -71,25 +74,20 @@ fn inc() { } } + TimeoutFuture::new(10).await; + assert_eq!( div.inner_html(), "

    Total: 6 from 3 counters.

    • 1
    • 2
    • 3
    " + Counters

    Total: \ + 6 from 3 \ + counters.

    • 1
    • 2
    • 3
    " ); // remove the first counter @@ -101,20 +99,17 @@ fn inc() { .unchecked_into::() .click(); + TimeoutFuture::new(10).await; + assert_eq!( div.inner_html(), "

    Total: 5 from 2 counters.

    • 2
    • 3
    " + Counters

    Total: \ + 5 from 2 \ + counters.

    • 2
    • 3
    " ); }