How to use the nock.back.fixtures function in nock

To help you get started, we’ve selected a few nock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ewnd9 / media-center / test / helpers / nock.js View on Github external
function setupNock(filename, functionName, dirName) {
  nockBack.fixtures = dirName || __dirname + '/../fixtures'; // causes bugs with ava concurrent run mode

  const data = filename.split('/');
  const fixtureName = data[data.length - 1].split('.')[0] + '/' + functionName + '.json';
  let nockDone = null;

  const options = {
    // https://github.com/node-nock/nock/issues/484#issuecomment-191822034
    after: () => nock.enableNetConnect(/(127.0.0.1|localhost)/),
    afterRecord: outputs => outputs.filter(o => !o.scope.match(/(127.0.0.1|localhost)/))
  };

  const beforeFn = () => {
    nockBack.setMode('record');
    nockBack(fixtureName, options, callback => nockDone = callback);
  };
github muxinc / mux-node-sdk / test / helper.js View on Github external
before(() => {
  nockBack.setMode(nockBack.currentMode);
  // If we decide to use nock with other modules we should move this to a test helper
  nockBack.fixtures = path.join(__dirname, '/nockFixtures');
});
github drewcummins / hodlol / test / test-kucoin.js View on Github external
var expect = require('chai').expect;
let kucoin = require('../app/client/kucoin');
var nockBack = require('nock').back;

nockBack.fixtures = './test/fixtures/';
nockBack.setMode('record');

describe('Kucoin init', function() {
  it('should initialize properly', function() {
    expect(kucoin.exchange).to.equal("Kucoin");
  });
});

describe('Kucoin.getTicker()', function() {
  it('should get ticker value', function() {

    return nockBack('kucoin-ticker.json')
    .then(async ({nockDone, context}) => {
      const coin = "VEN";
      const market = "BTC"
      const pair = `${coin}-${market}`;