No description
Find a file
2023-03-15 00:14:13 +00:00
example Renamed project to jsFetchMoch 2023-03-14 23:42:48 +00:00
src Renamed project to jsFetchMoch 2023-03-14 23:42:48 +00:00
.gitignore Version 0.1.0 2023-03-14 23:35:44 +00:00
changelog.md Fixed package meta 2023-03-15 00:14:13 +00:00
jsFetchMock.nimble Fixed package meta 2023-03-15 00:14:13 +00:00
license Version 0.1.0 2023-03-14 23:35:44 +00:00
readme.md Version 0.1.0 2023-03-14 23:35:44 +00:00

JS Fetch Mock

A simple lib to intercept Javascript fetch to capture or edit the data

You can use it in Nim and Javascript!

Examples

Javascript

You can see the full example at example/js

newFetchMock("example", (err, url, response, config) => {
  return `{"name": "John"}` // check, edit and replace the data here
})
fetch("../data.json")
  .then((x) => x.text())
  .then((txt) => {
    console.log(txt)
  })
deleteFetchMock("example")

Nim

You can see the example mocking a JS fetch at example/nim

Documentation

template newFetchMock*(name: cstring; cb: untyped): untyped

Add a mock with name and callback

It exposes to cb: error, url, body and configs

Example:

discard newFetchMock("example"):
  echo body

proc deleteFetchMock*(name: cstring): bool

Removes the mock by name

Example:

discard deleteFetchMock("example")

License

MIT