diff options
author | Mariusz Sygnowski <mariusz.sygnowski@nokia.com> | 2019-04-09 11:32:23 +0200 |
---|---|---|
committer | Mariusz Sygnowski <mariusz.sygnowski@nokia.com> | 2019-04-10 13:01:08 +0200 |
commit | 12af2f20c2313a3fc1fe5761eaf2e885d3c8b751 (patch) | |
tree | 6f57a164d871ec29f554513634f7e406af5867cf /test/app/networking | |
parent | cae868635ebe867b85223b056a5243c128192cbe (diff) |
Fixing failing test
+ covarage improvement
Change-Id: Id13e334cc1493274081758079a1f896f35af6b80
Issue-ID: AAI-2341
Signed-off-by: Mariusz Sygnowski<mariusz.sygnowski@nokia.com>
Diffstat (limited to 'test/app/networking')
-rw-r--r-- | test/app/networking/NetworkCalls.test.js | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/test/app/networking/NetworkCalls.test.js b/test/app/networking/NetworkCalls.test.js index 373fbac..a3b6176 100644 --- a/test/app/networking/NetworkCalls.test.js +++ b/test/app/networking/NetworkCalls.test.js @@ -90,34 +90,53 @@ describe("Network Utils", () => { describe('#getRequest', () => { it("should fetch any request", () => { - const json = suite.sandbox.stub(); - const fetchPromise = Promise.resolve({json}); - global.fetch = suite.sandbox.stub(); - - global.fetch - .withArgs('URL', { - credentials: 'same-origin', - method: 'GET' - }) - .returns(fetchPromise); - - NetworkCalls.getRequest("URL", "GET"); - - return fetchPromise.then(() => { - sinon.assert.calledOnce(json); - }); + // given + global.fetch = suite.sandbox.stub(); + const json = suite.sandbox.stub(); + const url = "localhost"; + + global.fetch + .withArgs(url, { + credentials: 'same-origin', + method: 'GET' + }) + .returns(json); + + // when + const request = NetworkCalls.getRequest(url, "GET"); + + //then + expect(request).toBe(json) + sinon.assert.calledOnce(global.fetch); }); }); describe('#genericRequest', () => { it('should fetch any generic request', () => { + // given global.fetch = suite.sandbox.stub(); const then = suite.sandbox.stub(); fetch.returns({then}); + + // when NetworkCalls.genericRequest("localhost", "/relativeUrl", "GET"); + // then expect(then.firstCall.args[0]({json: () => "d"})).toEqual("d"); + sinon.assert.calledOnce(fetch); + }); + it('should fetch any generic request - non relative', () => { + // given + global.fetch = suite.sandbox.stub(); + const then = suite.sandbox.stub(); + fetch.returns({then}); + + // when + NetworkCalls.genericRequest("localhost", false, "GET"); + + // then + expect(then.firstCall.args[0]({json: () => "d"})).toEqual("d"); sinon.assert.calledOnce(fetch); }); }); |