How to use the proxyquire function in proxyquire

To help you get started, we’ve selected a few proxyquire 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 pilwon / node-yahoo-finance / lib / quote.spec.js View on Github external
it('correctly transforms current Yahoo response (2017-05-21)', async () => {
      const quote = proxyquire('./quote', stubbedFor('quoteJson')).default;
      const result = await quote({
        // Note, these aren't actually used in this test - data from a fixture
        symbol: 'MSFT'
      });

      result.price.symbol.should.equal('MSFT');

      // check dates
      result.summaryDetail.exDividendDate.should.be.a('date');
      result.calendarEvents.exDividendDate.should.be.a('date');
      result.calendarEvents.dividendDate.should.be.a('date');
      result.upgradeDowngradeHistory.history[0].epochGradeDate.should.be.a('date');
      result.upgradeDowngradeHistory.history[1].epochGradeDate.should.be.a('date');
      result.price.preMarketTime.should.be.a('date');
      result.price.postMarketTime.should.be.a('date');
      result.price.regularMarketTime.should.be.a('date');
github ewnd9 / media-center / test / fixtures / create-app.js View on Github external
default: createTraktService
    },
    './torrents-service': {
      default: createTorrentsService
    }
  };

  if (playerServiceMock) {
    servicesMocks['./player-service'] = playerServiceMock;
  }

  if (marksServiceMock) {
    servicesMocks['./marks-service'] = marksServiceMock;
  }

  const createApp = proxyquire('../../src/index', {
    './config': {
      dbPath: tmpDir,
      mediaPath: tmpDir,
      mediaTrashPath: tmpTrashDir,
      screenshotPath: tmpDir,
      trakt: traktMock,
      port: (Math.random() * 64514) | 0 + 1024
    },
    './services/index': proxyquire('../../src/services/index', servicesMocks),
    './server': proxyquire('../../src/server', {
      './routes/youtube': proxyquire('../../src/routes/youtube', {
        execa: () => Promise.resolve({ stdout: 'youtube-url' })
      })
    })
  }).default;
github moroshko / react-autosuggest / test / Autosuggest.js View on Github external
import proxyquire from 'proxyquire';
import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import SyntheticEvent from 'react/lib/SyntheticEvent';

chai.use(sinonChai);

const Autosuggest = proxyquire('../src/Autosuggest', { debounce: fn => fn });
const Simulate = TestUtils.Simulate;
const SimulateNative = TestUtils.SimulateNative;
const suburbObjects = [
  { suburb: 'Cheltenham', postcode: '3192' },
  { suburb: 'Mill Park', postcode: '3083' },
  { suburb: 'Mordialloc', postcode: '3195' },
  { suburb: 'Nunawading', postcode: '3131' }
];
const stringSuburbs = suburbObjects.map(suburbObj => suburbObj.suburb);
const reactAttributesRegex = / data-react[-\w]+="[^"]+"/g;
let autosuggest, input, suggestions;
const onSuggestionSelected = sinon.spy();
const onSuggestionFocused = sinon.spy();
const onSuggestionUnfocused = sinon.spy();
const onChange = sinon.spy();
const onBlur = sinon.spy();
github novemberborn / hullabaloo-config-manager / test / Verifier.js View on Github external
function requireWithCurrentEnv (env = {}) {
  const currentEnv = proxyquire('../build/currentEnv', {
    process: {
      env
    }
  })

  const Verifier_ = proxyquire('../build/Verifier', {
    './currentEnv': currentEnv
  })

  return proxyquire('..', {
    './currentEnv': currentEnv,
    './Verifier': Verifier_,
    './ResolvedConfig': proxyquire('../build/ResolvedConfig', {
      './Verifier': Verifier_
    })
  })
}
github jplayer / react-jPlayer / src / components / browserUnsupported / browserUnsupportedContainer.spec.jsx View on Github external
import React from 'react';
import expect from 'expect';
import proxyquire from 'proxyquire';

import containerSetup from '../../util/specHelpers/containerSetup.spec';

proxyquire.noCallThru();

const id = 'TestPlayer';
const mockBrowserUnsupported = () =&gt; <div>;
const BrowserUnsupportedContainer = proxyquire('./browserUnsupportedContainer', {
  './browserUnsupported': mockBrowserUnsupported,
}).default;
const setup = (jPlayers, props) =&gt; containerSetup(BrowserUnsupportedContainer, jPlayers, props);

describe('BrowserUnsupportedContainer', () =&gt; {
  let jPlayers;

  beforeEach(() =&gt; {
    jPlayers = {
      [id]: {
        mediaSettings: {},
      },
    };
  });

  it('renders BrowserUnsupported when the media is not supported', () =&gt; {</div>
github yangmillstheory / chunkify / src / fp / each.spec.ts View on Github external
it('should delegate a function, array length and options to range', () => {
    let range = stub().returns({
      catch: stub()
    });
    let {each} = proxyquire('./each', {
      '../iter/range': {range}
    });

    let tArray = [1, 2, 3];
    let options = {};
    each(tArray, stub(), options);

    expect(range.calledOnce).to.be.ok;
    expect(range.lastCall.args[0]).to.be.instanceOf(Function);
    expect(range.lastCall.args[1]).to.equal(tArray.length);
    expect(range.lastCall.args[2]).to.equal(options);
  });
github travel-and-help / start-kit / src / front / app / features / watch-list / components / WatchList.integration.spec.js View on Github external
import proxyquire from 'proxyquire';

import React from 'react';
import { mount } from 'enzyme';
import { fromJS } from 'immutable';

const reactRouter = { hashHistory: {} };
const WatchList = proxyquire('./WatchList', {
    'react-router': reactRouter
}).default;

describe('WatchList', () => {
    let challenges,
        getWatchedChallenges,
        unWatchChallenge,
        wrapper,
        challengeTitles;

    beforeEach(() => {
        reactRouter.hashHistory.goBack = env.stub();
        challengeTitles = ['Feed a homeless person', 'Just do it!'];
        challenges = fromJS(challengeTitles.map(aChallenge));

        getWatchedChallenges = env.stub();
github jplayer / react-jPlayer / src / components / media / mediaContainer.spec.jsx View on Github external
import containerSetup from '../../util/specHelpers/containerSetup.spec';

import { setMedia, setOption, setVolume, setMute, setPlayHead, play, pause } from '../../actions/actions';

proxyquire.noCallThru();

let mockCurrentMedia;
const id = 'TestPlayer';
const mockMedia = ({ setCurrentMedia }) =&gt; {
  const mockRef = () =&gt; {
    setCurrentMedia(mockCurrentMedia);
  };

  return <audio>;
};
const MediaContainer = proxyquire('./mediaContainer', {
  './media': mockMedia,
}).default;
const setup = (jPlayers, props) =&gt; containerSetup(MediaContainer, jPlayers, {
  children: <audio>,
  ...props,
});

describe('MediaContainer', () =&gt; {
  let jPlayers;

  beforeEach(() =&gt; {
    jPlayers = {
      [id]: {
        src: 'www.test.com',
        playHeadPercent: 0,
        paused: false,</audio></audio>
github thealjey / webcompiler / spec / JSSpec.js View on Github external
beforeEach(function () {
          spyOn(fs, 'writeFile');
          mkdirp = jasmine.createSpy('mkdirp').and.callFake(function (path, callback) {
            callback('something bad happened');
          });
          JS = proxyquire('../lib/JS', {'./jsNodeCompileFile': jsNodeCompileFile, mkdirp});
          cmp = new JS();
          spyOn(cmp, 'validate').and.callFake(function (inPath, lintPaths, callback) {
            callback();
          });
          cmp.beFile('/path/to/the/input/file.js', '/path/to/the/output/file.js', Function.prototype,
                     '/lint/this/directory/too');
        });
github jplayer / react-jPlayer / src / components / playbackRateBar / playbackRateBarContainer.spec.jsx View on Github external
const mockTouchEvent = {
  touches: [
    {
      clientX: 20,
      clientY: 100,
    },
  ],
  preventDefault: expect.createSpy(),
};
const mockPlaybackRateBar = props =&gt; (
  <div> props.clickMoveBar(mockBar, mockClickEvent)}
    onTouchStart={() =&gt; props.touchMoveBar(mockBar, mockTouchEvent)}
  /&gt;
);
const PlaybackRateBarContainer = proxyquire('./playbackRateBarContainer', {
  './playbackRateBar': mockPlaybackRateBar,
}).default;
const setup = (jPlayers, props) =&gt; containerSetup(PlaybackRateBarContainer, jPlayers, props);

describe('PlaybackRateBarContainer', () =&gt; {
  let jPlayers;

  beforeEach(() =&gt; {
    jPlayers = {
      [id]: {
        maxPlaybackRate: 1,
        minPlaybackRate: 0,
      },
    };
  });
</div>

proxyquire

Proxies nodejs require in order to allow overriding dependencies during testing.

MIT
Latest version published 5 years ago

Package Health Score

59 / 100
Full package analysis