@greenlabs/rescript-nock

13.2.0 • Public • Published

rescript-nock

ReScript binding of nock

Install

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

Usage

With rescript-jest

open Jest
open Expect

describe("Test my module", () => {
  let setupNetworkScope = Nock.make("https://greenlabs.co.kr")
    ->Nock.get("/api/communities")
    ->Nock.replyAny(200, {
      "result": "OK"
    })
  describe("When call setup", () => {
    testPromise("Should network is mocked", () => {
      let scope = setupNetworkScope()

      Fetch.fetch("https://greenlabs.co.kr/api/communities")
      ->Promise.then(response => response->Fetch.Response.json)
      ->Promise.thenResolve(response => {
        expect(
          response
          ->Js.Json.decodeObject
          ->Belt.Option.flatMap(
            object => object->Js.Dict.get("result")->Belt.Option.flatMap(Js.Json.decodeString),
          ),
        )->toBe(Some("OK"))
        scope->Nock.done
      })
    })
  })
  
})

Readme

Keywords

Package Sidebar

Install

npm i @greenlabs/rescript-nock

Weekly Downloads

4

Version

13.2.0

License

MIT

Unpacked Size

4.77 kB

Total Files

5

Last publish

Collaborators

  • namenu
  • moondaddi
  • kimchhickey