reason-hooks-testing-library

0.2.1 • Public • Published

reason-hooks-testing-library

Reason bindings for 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:

{
  "bs-dev-dependencies": ["@glennsl/bs-jest", "reason-hooks-testing-library"]
}

Example

 
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

Package Sidebar

Install

npm i reason-hooks-testing-library

Weekly Downloads

1

Version

0.2.1

License

MIT

Unpacked Size

10.2 kB

Total Files

10

Last publish

Collaborators

  • beizhedenglong