DioxusLabs / DioxusLabs/docsite

Example from testing docs has compile warning and does not pass

Open
#489 0 comments 0 reactions 1 assignee Claimed by @ealmloff View on GitHub
bug documentation
Dominant language
Rust
Stars
206
Forks
208
Avg merge
1h 11m
Merged PRs (30d)
3

Description

**Problem**

Example test code from https://dioxuslabs.com/learn/0.6/cookbook/testing# has compile warning and does not pass

**Steps To Reproduce**

Steps to reproduce the behavior:

- Copy hook testing example from https://dioxuslabs.com/learn/0.6/cookbook/testing#hook-testing
- Compile the code.
- Run the test

**Expected behavior**

Example test compiles without warnings and passe

**Actual Behavior**

`thread::Scope` import is unused.

> running 1 test
> test test ... FAILED
>
> successes:
>
> successes:
>
> failures:
>
> ---- test stdout ----
>
> thread 'test' panicked at src/main.rs:24:17:
> assertion `left == right` failed
> left: 1
> right: 4

**Environment:**

- Dioxus version: 6.3
- Rust version: 1.85.0
- OS info: linux
- App platform: desktop

**Proposed solution**

Remove the unused input, and fix the test. I'm not sure whats wrong with it: that example is complex enough that its not obvious to me.

I'd also recommend adding a simpler example for cases which don't require testing mutations. Something like:

```Rust
#[cfg(test)]
mod tests {
use dioxus::prelude::*;

fn assert_rsx_eq(first: Element, second: Element) {
let first = dioxus_ssr::render_element(first);
let second = dioxus_ssr::render_element(second);
pretty_assertions::assert_str_eq!(first, second);
}

fn test_hook_simple(mut check: impl FnMut() + 'static) {
fn mock_app() -> Element {
rsx! {
div {}
}
}

let vdom = VirtualDom::new(mock_app);

vdom.in_runtime(|| {
ScopeId::ROOT.in_runtime(|| {
check();
})
})
}

#[test]
fn example() {
test_hook_simple(|| {
// Example use of a hook which requires the Dioxus runtime to be present
let signal = use_signal(|| "Hello".to_string());
assert_rsx_eq(
rsx! {
span {
{signal}
" world"
}
},
rsx! {
span { "Hello world" }
},
)
});
}
}
```

This examples uses a test utility I wrote and used for some actual testing in a real library, and proved quite useful.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.