menu

Testing Library

Simple and complete DOM testing utilities that encourage good testing practices.

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# General Help
view-forward
# Angular Help
view-forward
# Cypress Help
view-forward
# DOM Help
view-forward
# React Help
view-forward
# Svelte Help
view-forward
# TestCafe Help
view-forward
# Vue Help
view-forward
Team

Is there a way to test for a DOM element that shows up in a custom hook?

February 11, 2020 at 6:24pm

Is there a way to test for a DOM element that shows up in a custom hook?

February 11, 2020 at 6:24pm
I am using the react-hooks part of the library. I am using the renderHook function. Is it possible to get DOM elements from that to see if they have been rendered by the custom hook?

February 11, 2020 at 6:44pm
I'm not sure if I understand correctly what you mean, but:
  • when using /react-hooks you'll get the exact result that your hook returns. If your hook is returning some elements, then you can check them directly from result returned
  • you can also test hooks with just /react by generating a dumb component in your test that uses the hook. Then, as usual, you are able to look for whatever DOM element you need
Edited
  • reply
  • like
that makes sense
  • reply
  • like
I have a dialog that pops up for a confirmation if a condition is true. I will test for the dom element in a component that uses the custom hook. Thank you for your help.
  • reply
  • like
It looks like what you want to test then is if the dialog appears within a component under certain condition, not matter if implemented with a hook or not :) so I would just add a test to that component which reproduces steps from the user and then check the dialog is there when expected!
Edited
  • reply
  • like