Open
Description
After upgrading to v2, the code copied from the documentation is not functioning properly.
function waitForRequest(method: string, url: string) {
let requestId = ''
return new Promise<MockedRequest>((resolve, reject) => {
server.events.on('request:start', (req) => {
const matchesMethod = req.method.toLowerCase() === method.toLowerCase()
const matchesUrl = matchRequestUrl(req.url, url).matches
if (matchesMethod && matchesUrl) {
requestId = req.id
}
})
server.events.on('request:match', (req) => {
if (req.id === requestId) {
resolve(req)
}
})
server.events.on('request:unhandled', (req) => {
if (req.id === requestId) {
reject(
new Error(`The ${req.method} ${req.url.href} request was unhandled.`),
)
}
})
})
}
Is it still possible to retrieve a request reference and write request assertions (i.e., determine if the correct request payload was sent) in v2? I am unable to find this information in the new documentation.
Metadata
Metadata
Assignees
Labels
No labels