diff --git a/package.json b/package.json index 2406e30..aa36ae3 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "babel-register": "^6.9.0", "eslint": "^2.4.0", "eslint-config-openstack": "2.0.0", + "fetch-mock": "^5.0.5", "istanbul": "^1.0.0-alpha.2", "jasmine": "^2.4.1", "karma": "^1.1.1", diff --git a/src/index.js b/src/index.js index b86fa54..ca913cc 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,13 @@ import 'babel-polyfill'; -import fetch from 'isomorphic-fetch'; +import 'isomorphic-fetch'; import log from 'loglevel'; log.setLevel('INFO'); export default class Test { - getUrl(url) { + getUrl (url) { return fetch(url) .then((response) => { - log.info(response.status); return response; }); } diff --git a/test/unit/indexTest.js b/test/unit/indexTest.js index 1b0edf2..c13a23f 100644 --- a/test/unit/indexTest.js +++ b/test/unit/indexTest.js @@ -1,8 +1,32 @@ import Test from "../../src/index.js"; +const FetchMock = require('fetch-mock'); + describe("Simple test", () => { + + afterEach(() => { + FetchMock.reset(); + }); + it("should export a class", () => { let t = new Test(); expect(t).toBeDefined(); }); + + it("should retrieve URL's", (done) => { + FetchMock.get("http://example.com/", { + status: 200, + body: "This is a test" + }); + + let t = new Test(); + t.getUrl("http://example.com/") + .then((response) => { + return response.text(); + }) + .then((body) => { + expect(body).toEqual("This is a test"); + done(); + }); + }); });