Skip to content

Instantly share code, notes, and snippets.

@daneov
Created January 8, 2018 15:02
Show Gist options
  • Save daneov/4140862bac9dc5b1445607935004651e to your computer and use it in GitHub Desktop.
Save daneov/4140862bac9dc5b1445607935004651e to your computer and use it in GitHub Desktop.
function mockWithType(contentType, httpMethod = "GET", referenceUrl = "/") {
const urlResult = baseUrl + referenceUrl
console.log("Mocked '" + urlResult + "' for " + httpMethod);
fetchMock.mock(
(url, opts) => {
return url === urlResult && opts && opts.headers && opts.headers.get('Content-Type') === contentType
},
{
number: 200,
body: {}
},
{
method: httpMethod
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment