error_boundary.rs 857 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. use dioxus::prelude::*;
  2. use futures_util::Future;
  3. #[test]
  4. fn catches_panic() {
  5. let mut dom = VirtualDom::new(app);
  6. let a = dom.rebuild();
  7. }
  8. fn app(cx: Scope) -> Element {
  9. cx.render(rsx! {
  10. div {
  11. PanicChild {}
  12. }
  13. })
  14. }
  15. fn PanicChild(cx: Scope) -> Element {
  16. panic!("Rendering panicked for whatever reason");
  17. cx.render(rsx! {
  18. h1 { "It works!" }
  19. })
  20. }
  21. fn ThrowChild(cx: Scope) -> Element {
  22. cx.throw(std::io::Error::new(std::io::ErrorKind::AddrInUse, "asd"))?;
  23. let g: i32 = "123123".parse().throw(cx)?;
  24. cx.render(rsx! {
  25. div {}
  26. })
  27. }
  28. fn custom_allocator(cx: Scope) -> Element {
  29. let g = String::new();
  30. let p = g.as_str();
  31. let g2 = cx.use_hook(|| 123);
  32. // cx.spawn(async move {
  33. // //
  34. // // println!("Thig is {p}");
  35. // });
  36. None
  37. }