I was trying to mock an external API for my unit tests with the SinonJs framework. For mocking the API I use the fake saver from SinonJS (http://ift.tt/1RRkcyz) Unfortunately I was not able at the moment to send any request to my fake server... Does anybody know what I'm doing wrong in my test:
import expect from 'expect';
import { searchForProducts } from 'api/ProductAPI';
import emptyResults from 'api/ProductAPI_EmptyResult.json';
describe('ProductAPI', () => {
let server;
before(function () {
server = sinon.fakeServer.create();
server.respondWith(
"GET",
"http://ift.tt/1VY9vNP",
[200, { "Content-Type": "application/json" }, JSON.stringify(emptyResults)]
);
});
it('product search with working API ', () => {
server.respond();
searchForProducts('tv').then(
(data) => {
console.log('success');
},
(error) => {
console.log('error');
});
//dummy expect
expect(
'test'
).toEqual('test');
});
});
Some information for the code: the searchForProducts method is a function which makes a rest call with the help of a HTTP client called axios(http://ift.tt/X7rcPX)
Thank you for your help!
Greetz
Aucun commentaire:
Enregistrer un commentaire