Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beizhedenglong/reason-hooks-testing-library
ReasonML bindings for react-hooks-testing-library
https://github.com/beizhedenglong/reason-hooks-testing-library
react-hooks reason-react reasonml reasonml-bindings
Last synced: about 2 months ago
JSON representation
ReasonML bindings for react-hooks-testing-library
- Host: GitHub
- URL: https://github.com/beizhedenglong/reason-hooks-testing-library
- Owner: beizhedenglong
- License: mit
- Created: 2019-05-16T14:37:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-13T12:59:10.000Z (about 4 years ago)
- Last Synced: 2024-07-05T15:31:25.456Z (3 months ago)
- Topics: react-hooks, reason-react, reasonml, reasonml-bindings
- Language: Reason
- Homepage:
- Size: 78.1 KB
- Stars: 23
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - reason-hooks-testing-library - hooks-testing-library | beizhedenglong | 24 | (Reason)
README
# reason-hooks-testing-library
Reason bindings for [`react-hooks-testing-library`](https://github.com/mpeyper/react-hooks-testing-library).
## Installation
`npm install --save-dev reason-hooks-testing-library`Then add `reason-hooks-testing-library` to `bs-dev-dependencies` in your `bsconfig.json`:
```json
{
"bs-dev-dependencies": ["@glennsl/bs-jest", "reason-hooks-testing-library"]
}
```## Example
```reason
open Jest;
open Expect;
open ReasonHooksTestingLibrary.Testing;type counterType = {
counter: int,
set: (int => int) => unit,
};
let useCounter = initial => {
let (counter, set) = React.useState(() => initial);
{counter, set};
};describe("useCounter", () => {
open Result;
let container = renderHook(() => useCounter(0), ());
test("counter is 0", () =>
expect(container->result->current.counter) |> toEqual(0)
);
test("counter is 1", () => {
act(() => container->result->current.set(prev => prev + 1));
expect(container->result->current.counter) |> toEqual(1);
});
test("counter is 2", () => {
act(() => container->result->current.set(prev => prev + 1));
expect(container->result->current.counter) |> toEqual(2);
});
});```
[More examples](https://github.com/beizhedenglong/reason-hooks-testing-library/tree/master/__tests__)