Skip to content

Instantly share code, notes, and snippets.

@nivsherf
Last active January 16, 2021 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nivsherf/4934b3cfae657a93302f11df207e32b4 to your computer and use it in GitHub Desktop.
Save nivsherf/4934b3cfae657a93302f11df207e32b4 to your computer and use it in GitHub Desktop.
Global RegExp in nock path
'use strict'
const nock = require('./index');
const request = require('superagent');
const testMock = async (regexp) => {
const scope = nock('https://api.github.com')
.get(regexp).reply(200, { foo: 'bar' });
try {
const response = await request.get('https://api.github.com/repos/atom/atom/license');
scope.done();
console.log('Got a response!', regexp, response.body);
} catch (err) {
console.log('error for regexp', regexp, err);
throw err;
}
}
testMock(/repos.*/).then(() => testMock(/repos.*/g)).catch(() => process.exit(1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment