safety.rs 823 B

1234567891011121314151617181920212223242526
  1. //! Tests related to safety of the library.
  2. use dioxus::prelude::*;
  3. use dioxus_core::SuspenseContext;
  4. /// Ensure no issues with not calling rebuild
  5. #[test]
  6. fn root_node_isnt_null() {
  7. let dom = VirtualDom::new(|cx| render!("Hello world!"));
  8. let scope = dom.base_scope();
  9. // We haven't built the tree, so trying to get out the root node should fail
  10. assert!(scope.try_root_node().is_none());
  11. // There should be no way to gain an invalid pointer
  12. assert!(scope.current_frame().node.get().is_null());
  13. assert!(scope.previous_frame().node.get().is_null());
  14. // The height should be 0
  15. assert_eq!(scope.height(), 0);
  16. // There should be a default suspense context
  17. // todo: there should also be a default error boundary
  18. assert!(scope.has_context::<SuspenseContext>().is_some());
  19. }