fake-fetch
fake window.fetch for tests.
Installation
$ npm install fake-fetch --save-dev
Usage
var fakeFetch = ; ;; ;
API
install
Mock window.fetch
before doing anything.
restore
Restore window.fetch
.
getUrl
Returns request URL.
getMethod
Returns request method. Default is 'get'.
getBody
Returns message body. Default is '' (empty string).
getRequestHeaders
Returns request headers. Default is {} (empty object).
getOptions
Returns request options. Default is {} (empty object)
called (Boolean getter)
Check whether this instance of fakeFetch was ever called
respondWith(data, options)
data
Type: object
The object to be sent as request-body.
options
Type: object
Custom Response options, see Response
Remarks
You may find necessary to use browserify before using fake-fetch within your specs, e.g.
// karma.conf.jspreprocessors: './node_modules/fake-fetch/index.js': 'browserify'
Real-life usage example can be found here https://github.com/msn0/file-downloader/blob/master/test.js
License
MIT © Michał Jezierski