polish: change in cx to cx
This commit is contained in:
1 parent
0ded32e184
commit
9971ff215d
21 files changed
+426
-320
No files matched your search
@@ -0,0 +1,41 @@
|
||||
use dioxus::{nodes::VSuspended, prelude::*, DomEdit, TestDom};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use DomEdit::*;
|
||||
|
||||
mod test_logging;
|
||||
|
||||
fn new_dom() -> TestDom {
|
||||
const IS_LOGGING_ENABLED: bool = false;
|
||||
test_logging::set_up_logging(IS_LOGGING_ENABLED);
|
||||
TestDom::new()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_state_test() {
|
||||
struct MySharedState(&'static str);
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
cx.provide_state(|| MySharedState("world!"));
|
||||
rsx!(cx, Child {})
|
||||
};
|
||||
|
||||
static Child: FC<()> = |cx| {
|
||||
let shared = cx.consume_state::<MySharedState>()?;
|
||||
rsx!(cx, "Hello, {shared.0}")
|
||||
};
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let Mutations { edits, .. } = dom.rebuild();
|
||||
|
||||
assert_eq!(
|
||||
edits,
|
||||
[
|
||||
CreateTextNode {
|
||||
id: 0,
|
||||
text: "Hello, world!"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
]
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user