javascript - Getting Error: getaddrinfo ENOTFOUND using https -
i have created simple class:
import https 'https'; class request { constructor(opts) { this.hostname = opts.hostname; } init(method, path, data = {}) { const optsreq = { hostname: this.hostname, path: path, method: method }; return new promise((resolve, reject) => { const req = https.request(optsreq, (response) => resolve(response)); req.on('error', (error) => { console.log(error); reject(error); }); req.end(json.stringify(data)); }); } get(path) { return this.init('get', path); } post(path, data) { return this.init('post', path, data); } put(path) { return this.init('put', path); } delete(path) { return this.init('delete', path); } patch(path) { return this.init('patch', path); } } export default request;
and i'm trying test it:
import chai, { expect } 'chai'; import chaiaspromised 'chai-as-promised'; import sinon 'sinon'; import request '../src/request'; chai.use(chaiaspromised); describe('request', () => { const hostname = 'fake-server.com'; let server; before(() => { server = sinon.fakeserver.create(); server.respondwith( 'get', `https://${hostname}/api/entities`, [ 200, { 'content-type': 'application/json' }, json.stringify({ entities: 1 })] ); }); it('receive http 200 status code request', () => { const opts = { hostname }; const req = new request(opts).get('/api/entities'); return expect(req).to.eventually.have.property('entities'); }); after(() => { server.restore(); }); });
unfortunately whatever hostname use following error:
[error: getaddrinfo enotfound fake-server.com fake-server.com:443]
any idea?
Comments
Post a Comment