-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Minor fixes for tests #4686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Minor fixes for tests #4686
Changes from all commits
18c6575
5c05cb7
3208be4
a8910cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,22 +217,6 @@ fn suspended_nodes_dont_trigger_effects() { | |
} | ||
} | ||
|
||
#[component] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component was unused |
||
fn RerendersFrequently() -> Element { | ||
let mut count = use_signal(|| 0); | ||
|
||
use_future(move || async move { | ||
for _ in 0..100 { | ||
tokio::time::sleep(std::time::Duration::from_millis(10)).await; | ||
count.set(count() + 1); | ||
} | ||
}); | ||
|
||
rsx! { | ||
div { "rerenders frequently" } | ||
} | ||
} | ||
|
||
#[component] | ||
fn Child() -> Element { | ||
let mut future_resolved = use_signal(|| false); | ||
|
@@ -474,22 +458,6 @@ fn toggle_suspense() { | |
fn nested_suspense_resolves_client() { | ||
use Mutation::*; | ||
|
||
async fn poll_three_times() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exactly duplicated a function at the top of the file so removed for DRYness |
||
// Poll each task 3 times | ||
let mut count = 0; | ||
poll_fn(|cx| { | ||
println!("polling... {}", count); | ||
if count < 3 { | ||
count += 1; | ||
cx.waker().wake_by_ref(); | ||
Poll::Pending | ||
} else { | ||
Poll::Ready(()) | ||
} | ||
}) | ||
.await; | ||
} | ||
|
||
fn app() -> Element { | ||
rsx! { | ||
SuspenseBoundary { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if this level of checking was overkill, but it checks that the signals are working... |
||
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] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have misunderstood but I don't think this test generates any errors to bubble? I've marked it as ignore to flag it, but I'm open to changing or removing it.