rescript-hooks-testing-library

    0.1.0 • Public • Published

    rescript-hooks-testing-library

    ReScript bindings for react-hooks-testing-library.


    Installation

    npm install --save-dev rescript-hooks-testing-library

    Then add rescript-hooks-testing-library to bs-dev-dependencies in your bsconfig.json:

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

    Example

    open Jest
    open Expect
    open Testing
    
    type counterType = {
      counter: int,
      set: (int => int) => unit,
    }
    
    let useCounter = initial => {
      let (counter, set) = React.useState(() => initial)
      {counter: counter, set: 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 usage examples

    1. Tests
    2. react-hooks-testing-library documentation

    Install

    npm i rescript-hooks-testing-library

    DownloadsWeekly Downloads

    166

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    6.28 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar