From 914c7fa88d09ffc24bcc61b97b8846effa8e84c2 Mon Sep 17 00:00:00 2001 From: seancrater Date: Wed, 21 Feb 2018 18:26:32 -0500 Subject: [PATCH] Getting coverage up to 100% and testing for errors --- .gitignore | 1 + .npmignore | 1 + tests/index.test.js | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b512c09..7cafbdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +coverage node_modules \ No newline at end of file diff --git a/.npmignore b/.npmignore index 71493a0..148061d 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,6 @@ .DS_Store .gitignore +coverage src tests yarn.lock \ No newline at end of file diff --git a/tests/index.test.js b/tests/index.test.js index 4595f06..fbf283b 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -12,17 +12,28 @@ fetch.mockResponses( [ new Error('404 Not Found'), { status: 404 } ] ); -const mockFetch = fetchMultiple(mockUrls); +const resolvingFetch = fetchMultiple(mockUrls); + +fetch.mockReject('404 Not Found'); +const failingFetch = fetchMultiple({ '/undefined.text': 'text' }); it('works as a promise', () => { - expect(mockFetch.resolves); + expect(resolvingFetch.resolves); }); -it('returns the correct values', () => { - expect(mockFetch.then(data => { +it('returns the correct values for functional endpoints', () => { + expect(resolvingFetch.then(data => { return data === { '/data.json': { data: true }, 'text.txt': 'Some example text' } })); +}); + +it('returns an error for failing endpoints', () => { + expect(failingFetch.then(data => { + return data === { + '/undefined.text': '404 Not Found' + } + })); }); \ No newline at end of file