I'm trying to test a node API in mocha, but I get no response from the API request that works fine in browser.
Here is the response in browser:
Response in browser: {"succes":true}
And this is the API test that is not working:
var request = require("request");
var expect = require("chai").expect;
describe("API TEST", function(){
it("Should return true", function(done){
request.get({ url: "https://skilltree.benis.hu/apitest" },
function(error, response, body) {
console.log(response);
done();
});
});
});
Result:
API TEST -> undefined (response=undefined)
But the testing syntax seems fine, since it works with a public API:
describe("API TEST", function(){
it("Should return true", function(done){
request.get({ url: "https://anapioficeandfire.com/api/characters/583" },
function(error, response, body) {
console.log(response);
done();
});
});
});
Result: Result was a bunch of response data.
Tried to test it in POSTMAN, MIGHT have found the issue, not sure: Couldn't get response.
Possible solutions:
Turn off ssl certificate verification <- did this one Turned off SSL Certificate verification in postman, and it worked:
Response was the same as in browser: {"succes":true}
I tried to find a way to disable it in code too for testing, but I had no luck finding one. This is pretty much the first time I am testing anything.