Skip to content

Commit

Permalink
adds supporting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samrocksc committed Nov 14, 2017
1 parent 8b36e31 commit 83b5f33
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 135 deletions.
124 changes: 0 additions & 124 deletions built-test/index.js

This file was deleted.

1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'isomorphic-fetch';
import queryString from 'query-string';

function howard(path, options) {
return fetch(path, options);
Expand Down
37 changes: 26 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ const config = {
url: 'https://shoutinginfrench.com'
}

const mockArrayBuffer = new ArrayBuffer;

const isNode = (process && process.release && process.release.name === 'node');

describe('Howard should', () => {

beforeEach(function() {
fetchMock.getOnce(config.url + '/get', pass)
fetchMock.postOnce(config.url + '/post', pass)
fetchMock.postOnce(config.url + '/checkAuth', { status: 301 });
fetchMock.getOnce(config.url + '/fail', { status: 404 })
fetchMock.getOnce(config.url + '/blob', img);
fetchMock.getOnce(config.url + '/qs?id=1', pass);
fetchMock.getOnce(config.url + '/arrayBuffer', mockArrayBuffer);
});

//const api = howard(config);
Expand Down Expand Up @@ -52,18 +57,20 @@ describe('Howard should', () => {
return expect(request).resolves.toMatchObject(expect.objectContaining({status: 404}));
})

it.skip('handle a query string', (done) => {
done();
// Query Strings
it('handle a query string', () => {
const api = withDefaults(config);
const options = {
method: 'GET',
query: {
id: 1
}
}
const request = json(api('/qs', options));
return expect(request).resolves.toEqual(pass);
});

it('receive a json error message', (done) => {
done();
})

it('should handle a status code non 200 below 400', (done) => {
done();
})

// JSON
it('handle json()', () => {
const request = json(howard(config.url + '/get'))
return expect(request).resolves.toMatchObject(pass);
Expand All @@ -75,6 +82,7 @@ describe('Howard should', () => {
})


// Text
it('handle text()', () => {
const request = text(howard(config.url + '/get'))
return expect(request).resolves.toEqual(JSON.stringify(pass));
Expand All @@ -85,6 +93,7 @@ describe('Howard should', () => {
return expect(request).resolves.toEqual(JSON.stringify(pass));
})

// Blobs
it('handle blob()', function() {
if (isNode) {
this.skip();
Expand Down Expand Up @@ -164,6 +173,12 @@ describe('Howard should', () => {
fetchMock.getOnce(config.url + '/buffer', {})
const request = buffer(howard(config.url + '/buffer'));
return expect(request).rejects.toMatchObject(new Error('Method not implemented'));
})
});

// withDefaults
it('is able to take defaults', function() {
const api = withDefaults(config);
const request = json(api('/get', { method: 'GET' }));
return expect(request).resolves.toEqual(pass);
});
});

0 comments on commit 83b5f33

Please sign in to comment.