A testing utils library
npm install @neovici/testingThe renderHook function allows you to test hooks in isolation for web components using Pion.js.
``typescript
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);
});
});
`
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
- initialProps: Initial props to pass to the hookwrapper`: A wrapper function to wrap the hook rendering
-