Add test for Api.jsonFetch
authorFrank Bessou <frank.bessou@logilab.fr>
Fri, 31 Mar 2017 14:57:56 +0200
changeset 61 dae8abf45c58
parent 60 c7d925006198
child 62 7708e602ffde
Add test for Api.jsonFetch
test/index.js
--- a/test/index.js	Fri Mar 31 13:40:42 2017 +0200
+++ b/test/index.js	Fri Mar 31 14:57:56 2017 +0200
@@ -382,4 +382,19 @@
             expect(url).to.be.equal('http://example.com/foo');
         });
     });
+
+    describe('jsonFetch', () => {
+        const baseUrl = 'http://example.com';
+        const anyUrl = 'http://xyz.com';
+        const validResponse = new window.Response('{}', {headers: {'content-type': 'application/json'}});
+
+        it('should call fetch function provided in constructor', () => {
+            const fetch = sinon.stub().resolves(validResponse);
+            const api = new Api(baseUrl, fetch);
+
+            api.jsonFetch(anyUrl);
+
+            expect(fetch.calledOnce).to.be.true;
+        });
+    });
 });