Skip to content

papandreou/fetchception

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fetchception

Build Status

Mock out network traffic from fetch in tests. Experiment based on idea from fileception and httpception. Utilizing the great modelling, inspection and diffing of HTTP conversations from messy and unexpected-messy.

const fileception = require('fileception');
const assert = require('assert');

it('should cleanly mock out fetch in the test', () => fetchception([
    {
        request: '/api/foo',
        response: {
            statusCode: 200,
            body: { foo: 'bar' }
        }
    }
], () => {
    return fetch('/api/foo')
        .then(res => res.json())
        .then(res => {
            assert.equal(res.foo, 'bar');
        });
}));

When the test is done, the fetch global will automatically be restored.

Packages

No packages published

Languages

  • JavaScript 100.0%