mirror of
https://github.com/thisago/jsfetchMock
synced 2026-01-15 05:31:38 +00:00
No description
| example | ||
| src | ||
| .gitignore | ||
| changelog.md | ||
| jsFetchMock.nimble | ||
| license | ||
| readme.md | ||
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