From 2001bd808fa0765a532f4b7d0ed50e0f6d60a0eb Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 21 Apr 2023 15:26:18 -0400 Subject: [PATCH] examples: fix broken `counters` tests (#915) --- examples/Makefile.toml | 2 +- examples/counters/Cargo.toml | 3 +- examples/counters/src/lib.rs | 4 +-- examples/counters/tests/mod.rs | 55 ++++------------------------------ 4 files changed, 10 insertions(+), 54 deletions(-) diff --git a/examples/Makefile.toml b/examples/Makefile.toml index 8bcc7ff54..273f651a0 100644 --- a/examples/Makefile.toml +++ b/examples/Makefile.toml @@ -7,7 +7,7 @@ CARGO_MAKE_WORKSPACE_EMULATION = true CARGO_MAKE_CRATE_WORKSPACE_MEMBERS = [ "counter", "counter_isomorphic", - #"counters", - FIXME: test compile errors + "counters", "counters_stable", "counter_without_macros", "error_boundary", diff --git a/examples/counters/Cargo.toml b/examples/counters/Cargo.toml index d4bc2d0a8..b91cdc114 100644 --- a/examples/counters/Cargo.toml +++ b/examples/counters/Cargo.toml @@ -11,4 +11,5 @@ console_error_panic_hook = "0.1.7" [dev-dependencies] 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 2e98f680a..237f66e74 100644 --- a/examples/counters/src/lib.rs +++ b/examples/counters/src/lib.rs @@ -38,7 +38,7 @@ pub fn Counters(cx: Scope) -> impl IntoView { }; view! { cx, - <> +
@@ -72,7 +72,7 @@ pub fn Counters(cx: Scope) -> impl IntoView { } /> - +
} } diff --git a/examples/counters/tests/mod.rs b/examples/counters/tests/mod.rs index 284f3e3c7..cb1967338 100644 --- a/examples/counters/tests/mod.rs +++ b/examples/counters/tests/mod.rs @@ -1,10 +1,11 @@ use wasm_bindgen_test::*; +use wasm_bindgen::JsCast; wasm_bindgen_test_configure!(run_in_browser); use leptos::*; use web_sys::HtmlElement; -use counters::{Counters, CountersProps}; +use counters::Counters; #[wasm_bindgen_test] fn inc() { @@ -24,7 +25,7 @@ fn inc() { add_counter.click(); // check HTML - assert_eq!(div.inner_html(), "

Total: 0 from 3 counters.

"); + assert_eq!(div.inner_html(), "

Total: 0 from 3 counters.

"); let counters = div .query_selector("ul") @@ -52,7 +53,7 @@ fn inc() { } } - assert_eq!(div.inner_html(), "

Total: 6 from 3 counters.

"); + assert_eq!(div.inner_html(), "

Total: 6 from 3 counters.

"); // remove the first counter counters @@ -63,51 +64,5 @@ fn inc() { .unchecked_into::() .click(); - assert_eq!(div.inner_html(), "

Total: 5 from 2 counters.

"); - - // decrement all by 1 - for idx in 0..counters.length() { - let counter = counters.item(idx).unwrap(); - let dec_button = counter - .first_child() - .unwrap() - .unchecked_into::(); - dec_button.click(); - } - - run_scope(create_runtime(), move |cx| { - // we can use RSX in test comparisons! - // note that if RSX template creation is bugged, this probably won't catch it - // (because the same bug will be reproduced in both sides of the assertion) - // so I use HTML tests for most internal testing like this - // but in user-land testing, RSX comparanda are cool - assert_eq!( - div.outer_html(), - view! { cx, -
- - - -

"Total: ""3"" from ""2"" counters."

-
    -
  • - - - "1" - - -
  • -
  • - - - "2" - - -
  • -
-
- } - .outer_html() - ); - }); + assert_eq!(div.inner_html(), "

Total: 5 from 2 counters.

  • 2
  • 3
"); }