error_boundary.rs 568 B

12345678910111213141516171819202122232425262728293031323334
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. #[test]
  4. fn catches_panic() {
  5. let mut dom = VirtualDom::new(app);
  6. _ = dom.rebuild();
  7. }
  8. fn app(cx: Scope) -> Element {
  9. cx.render(rsx! {
  10. div {
  11. h1 { "Title" }
  12. NoneChild {}
  13. ThrowChild {}
  14. }
  15. })
  16. }
  17. fn NoneChild(_cx: Scope) -> Element {
  18. None
  19. }
  20. fn ThrowChild(cx: Scope) -> Element {
  21. cx.throw(std::io::Error::new(std::io::ErrorKind::AddrInUse, "asd"))?;
  22. let _g: i32 = "123123".parse().throw(cx)?;
  23. cx.render(rsx! {
  24. div {}
  25. })
  26. }