A simple lib to intercept Javascript fetch to capture or edit the data
You can use it in Nim and 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")You can see the example mocking a JS fetch at example/nim
Add a mock with name and callback
It exposes to cb: error, url, body and configs
Example:
discard newFetchMock("example"):
echo bodyRemoves the mock by name
Example:
discard deleteFetchMock("example")MIT