Skip to content

Instantly share code, notes, and snippets.

@coder36
Created October 2, 2016 14:38
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save coder36/a5c6f37623a066e50bbe52dd258b77f0 to your computer and use it in GitHub Desktop.
Save coder36/a5c6f37623a066e50bbe52dd258b77f0 to your computer and use it in GitHub Desktop.
import sinonStubPromise from 'sinon-stub-promise';
import sinon from 'sinon'
sinonStubPromise(sinon)
let stubedFetch = sinon.stub(window, 'fetch') )
window.fetch.returns(Promise.resolve(mockApiResponse()));
function mockApiResponse(body = {}) {
return new window.Response(JSON.stringify(body), {
status: 200,
headers: { 'Content-type': 'application/json' }
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment