Minor fixes for tests (#4686)
* Suggested method for correcting integration tests * Use static atomics for simplicity This is consistent with the test immediately below. * Add assertions to some tests, comments to others This should fix a handful of tests that didn't correctly do their test. In other places, comments should make it clearer *why* tests are how they are. * Be consistent with existing imports * remove bad test * nit * fix compile errrs --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
679ba83652
commit
79693f8cff
12 files changed
+74
-77
No files matched your search
@@ -1,7 +1,7 @@
|
||||
#![allow(unused, non_upper_case_globals, non_snake_case)]
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::{generation, ElementId, NoOpMutations};
|
||||
use dioxus_core::{generation, ElementId, Mutation, NoOpMutations};
|
||||
use dioxus_signals::*;
|
||||
|
||||
#[test]
|
||||
@@ -22,35 +22,57 @@ fn create_signals_global() {
|
||||
}
|
||||
}
|
||||
|
||||
dom.rebuild_in_place();
|
||||
|
||||
fn create_without_cx() -> Signal<String> {
|
||||
Signal::new("hello world".to_string())
|
||||
}
|
||||
|
||||
let muts = dom.rebuild_to_vec();
|
||||
|
||||
// 11 edits: 10x CreateTextNode and 1x AppendChildren. These assertions rely on the VirtualDOM's
|
||||
// logic, but doing this means not introducing a dependency on a renderer.
|
||||
assert_eq!(11, muts.edits.len());
|
||||
for i in 0..10 {
|
||||
assert_eq!(
|
||||
&muts.edits[i],
|
||||
&Mutation::CreateTextNode {
|
||||
value: ("hello world".to_string()),
|
||||
id: ElementId(i + 1)
|
||||
}
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
&muts.edits[10],
|
||||
&Mutation::AppendChildren {
|
||||
id: ElementId(0),
|
||||
m: 10
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deref_signal() {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
static STRINGS_MATCH: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
let mut dom = VirtualDom::new(|| {
|
||||
rsx! {
|
||||
for _ in 0..10 {
|
||||
Child {}
|
||||
}
|
||||
}
|
||||
rsx! { Child {} }
|
||||
});
|
||||
|
||||
fn Child() -> Element {
|
||||
let signal = Signal::new("hello world".to_string());
|
||||
|
||||
// You can call signals like functions to get a Ref of their value.
|
||||
assert_eq!(&*signal(), "hello world");
|
||||
let result = &*signal();
|
||||
STRINGS_MATCH.store(result.eq("hello world"), Ordering::Relaxed);
|
||||
|
||||
rsx! {
|
||||
"hello world"
|
||||
"arbitrary text"
|
||||
}
|
||||
}
|
||||
|
||||
dom.rebuild_in_place();
|
||||
|
||||
assert!(STRINGS_MATCH.load(Ordering::Relaxed));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user