@neovici/testing
v2.1.1
Published
A testing utils library
Downloads
1,249
Readme
testing
Testing library utilities
renderHook
The renderHook function allows you to test hooks in isolation for web components using Pion.js.
Basic Usage
import { renderHook } from '@neovici/testing';
import { useState, useCallback } from '@pionjs/pion';
function useCounter() {
const [count, setCount] = useState(0);
const increment = useCallback(() => setCount(count + 1), [count]);
return { count, increment };
}
describe('useCounter', () => {
it('should return initial count', async () => {
const { result } = await renderHook(() => useCounter());
expect(result.current.count).to.equal(0);
});
});Return Value
The renderHook function returns an object with the following properties:
result: The current result of the hook executionrerender(newProps?): Re-render the hook with new propsunmount(): Unmount the hook and cleanupnextUpdate(message?, options?): Wait for the next updatehost: The host element (HTMLElement) for hooks that need direct host access
Options
initialProps: Initial props to pass to the hookwrapper: A wrapper function to wrap the hook rendering
