https://github.com/neovici/testing
Testing library utilities
https://github.com/neovici/testing
Last synced: 4 months ago
JSON representation
Testing library utilities
- Host: GitHub
- URL: https://github.com/neovici/testing
- Owner: Neovici
- License: apache-2.0
- Created: 2023-03-29T13:54:32.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-11T11:52:04.000Z (over 2 years ago)
- Last Synced: 2025-01-31T14:19:02.925Z (over 1 year ago)
- Language: TypeScript
- Size: 412 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# testing
Testing library utilities
## renderHook
The `renderHook` function allows you to test hooks in isolation for web components using Pion.js.
### Basic Usage
```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);
});
});
```
### Return Value
The `renderHook` function returns an object with the following properties:
- `result`: The current result of the hook execution
- `rerender(newProps?)`: Re-render the hook with new props
- `unmount()`: Unmount the hook and cleanup
- `nextUpdate(message?, options?)`: Wait for the next update
- `host`: The host element (HTMLElement) for hooks that need direct host access
### Options
- `initialProps`: Initial props to pass to the hook
- `wrapper`: A wrapper function to wrap the hook rendering