mocha - nock: reply is not a function -


i using nock intercept http requests in mocha / chai environment. using supertest , supertest-chai query own express server. this:

import { } 'mocha'; import chai, { should } 'chai';

import request 'supertest'; import supertestchai 'supertest-chai'; import joi 'joi'; import chaijoi 'chai-joi'; // others  function itrespondsto({ url, response, description, parameters = {} }) {   const maxage = parameters.maxage || serverconfig.defaultcacheage;   const params = parameters ? `${object.entries(parameters).map(([name, val]) => `&${name}=${val}`).join('&')}` : '';   const path = `/oembed?url=${encodeuricomponent(url)}${params}`;   const desc = description || `/oembed?url=${url}${params}`;   it(`should respond ${desc}`, (done) => {     request(server)       .get(path)       .expect(200)       .expect('content-type', /json/)       .expect('access-control-allow-methods', 'get')       .expect('cache-control', `public, max-age=${maxage}`)       .expect(res => object.values(oembed_types).should.include(res.body.type)) // [1]       .expect(res => joi.validate(res.body, oembed_schemas[res.body.type]).should.validate)       .expect(response)       .end(done);   }); }  describe('youtube endpoint', () => {   beforeeach(() => {     nock(/youtube\.com/)       .reply(200, remoteresponse);   });    aftereach(() => {     nock.restore();   });    itrespondsto({ url: 'https://youtu.be/m4hklkgvtgq', response });   itrespondsto({ url: 'https://www.youtube.com/embed/m4hklkgvtgq', response });   itrespondsto({ url: 'https://www.youtube.com/watch?v=m4hklkgvtgq', response });   itrespondsto({ url: 'https://www.youtube.com/?v=m4hklkgvtgq', response }); }); 

when run tests, first call of itrespondsto throw error:

1) youtube endpoint "before each" hook "should respond /oembed?url=https://youtu.be/m4hklkgvtgq":

typeerror: nock.reply not function

and first call of itrespondsto. if remove first call, next call throw error , on. have no idea why happening.

i found reason got error. had put get in between:

nock('https://www.youtube.com')   .get('/oembed')   .query(true)   .reply(200, remoteresponse); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -