Lesson:Testing Hooks in Vitest Browser Mode

Most times when using Vitest Browser Mode you will want to test against elements on the DOM, such as after rendering your React components with await render(<YourComponent/>).

But if you are writing React apps, sometimes it can be useful to test a React hook in isolation.

You can achieve this using the renderHook function (which is very similar to testing React hooks with React Testing Library):

import { renderHook } from 'vitest-browser-react';

This lesson we will quickly go over how to use it.

Loading full lesson...