'Nodejs MSW mock data
I've got a little problem with mocking request for nodejs api for my client.
import fetch from 'node-fetch';
import {setupServer} from "msw/node"
const server = setupServer(...handlers)
app.get('/data', async () => {
const res = await fetch("https://exampledata.com", {method:"POST", body: {...someParams}})
} )
and I want to write a handler that will return data from this fetch function? How can I achieve that?
I tried something like this:
import {rest} from "msw"
const handlers = [
rest.post("https://exampledata.com", (req,res,ctx)=> {
console.log("im fetching data")
})
]
but this doesnt work... somebody has an idea?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
