- 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);