npm.io
28.1.0 • Published 2 years ago

@greenlabs/rescript-jest

Licence
MIT
Version
28.1.0
Deps
0
Size
30 kB
Vulns
0
Weekly
0
Stars
49

rescript-jest

Install

npm i @greenlabs/rescript-jest --dev
or
yarn add @greenlabs/rescript-jest --dev
"bs-dev-dependencies": [
  "@greenlabs/rescript-jest"
]

Usage

open Jest
open Expect

describe("Test my module", () => {
  let myMockFunction = JestJs.make2((msg, msg2) => msg ++ msg2)
  let setup = () => {
    (myMockFunction->Mock.fn)("Hello ", "world!")
  }
  describe("When call setup", () => {
    beforeEach(() => {
      setup()
    })

    afterEach(() => {
      myMockFunction->Mock.mockClear
    })

    test("myFunction is should called", () => {
      expect(myMockFunction)->toBeCalled()
      expect(myMockFunction)->toBeCalledTimes(1)
    })

    test("myFunction is should called with 'Hello ', 'world!'", () => {
      expect(myMockFunction)->toBeCalledWith(("Hello ", "world!"))
    })

    test("myFunction return is 'Hello world!'", () => {
      expect(myMockFunction)->toReturnedWith("Hello world!")
    })
  })
  
})

Keywords