mod common;
use common::*;
use wasm_bindgen_test::wasm_bindgen_test;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
struct TestContext {
props: StoreAppProps,
}
fn setup() -> TestContext {
TestContext {
props: StoreAppProps::new(SubscriptionType::Map),
}
}
#[wasm_bindgen_test]
async fn on_init_with_initial_value_should_map_initial_value() {
let ctx = setup();
render_with_props::<StoreApp>(ctx.props).await;
assert_eq!(&inner_html().await, "0");
}
#[wasm_bindgen_test]
async fn on_store_value_changed_with_new_value_should_map_new_value() {
let ctx = setup();
render_with_props::<StoreApp>(ctx.props.clone()).await;
ctx.props.context.set_state(StoreState { value: 1 });
assert_eq!(&inner_html().await, "1");
}
#[wasm_bindgen_test]
async fn on_store_value_changed_with_new_value_should_rerender() {
let ctx = setup();
render_with_props::<StoreApp>(ctx.props.clone()).await;
let render_count = *ctx.props.render_count.borrow();
ctx.props.context.set_state(StoreState { value: 1 });
wait().await;
assert_eq!(*ctx.props.render_count.borrow(), render_count + 1);
}
#[wasm_bindgen_test]
async fn on_store_value_changed_with_trivial_value_change_should_not_rerender() {
let ctx = setup();
render_with_props::<StoreApp>(ctx.props.clone()).await;
let render_count = *ctx.props.render_count.borrow();
ctx.props.context.set_state(StoreState { value: 0 });
wait().await;
assert_eq!(*ctx.props.render_count.borrow(), render_count);
}