How to use the testdouble.constructor function in testdouble

To help you get started, we’ve selected a few testdouble 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 ethereumjs / ethereumjs-client / test / service / fastethereumservice.js View on Github external
tape('[FastEthereumService]', t => {
  class PeerPool extends EventEmitter { }
  PeerPool.prototype.open = td.func()
  td.replace('../../lib/net/peerpool', PeerPool)
  td.replace('../../lib/net/protocol/flowcontrol')
  const Chain = td.constructor()
  Chain.prototype.open = td.func()
  td.replace('../../lib/blockchain', { Chain })
  const EthProtocol = td.constructor()
  const LesProtocol = td.constructor()
  td.replace('../../lib/net/protocol/ethprotocol', EthProtocol)
  td.replace('../../lib/net/protocol/lesprotocol', LesProtocol)
  class FastSynchronizer extends EventEmitter { }
  FastSynchronizer.prototype.start = td.func()
  FastSynchronizer.prototype.stop = td.func()
  FastSynchronizer.prototype.open = td.func()
  td.replace('../../lib/sync/fastsync', FastSynchronizer)
  const FastEthereumService = require('../../lib/service/fastethereumservice')

  t.test('should initialize correctly', async (t) => {
    let service = new FastEthereumService()
    t.ok(service.synchronizer instanceof FastSynchronizer, 'fast mode')
    t.equals(service.name, 'eth', 'got name')
    t.end()
  })
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Expect.js View on Github external
beforeEach('create fakes', () => {
                FakeOpenStub = td.constructor(OpenStub);

                td.replace('../../../../lib/Protocol/Protobuf/Stubs/mysqlx_expect_pb', { Open: FakeOpenStub });
                Expect = require('../../../../lib/Protocol/Protobuf/Adapters/Expect');
                createCondition = td.replace(Expect, 'createCondition');
            });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Client.js View on Github external
beforeEach('create fakes', () => {
            FakeOkHandler = td.constructor(OkHandler);
            network = new PassThrough();

            td.replace('../../../lib/Protocol/ResponseHandlers/OkHandler', FakeOkHandler);
        });
github ethereumjs / ethereumjs-client / test / handler / leshandler.js View on Github external
const tape = require('tape-catch')
const td = require('testdouble')
const EventEmitter = require('events')
const Chain = td.constructor(require('../../lib/blockchain/chain'))
const Flow = td.constructor(require('../../lib/net/protocol/flowcontrol'))
const { LesHandler } = require('../../lib/handler')
const { defaultLogger } = require('../../lib/logging')
defaultLogger.silent = true

tape('[LesHandler]', t => {
  const pool = new EventEmitter()
  const chain = new Chain()
  const flow = new Flow()
  const handler = new LesHandler({ pool, chain, flow })
  const peer = { les: { send: td.func() } }
  const message = {
    name: 'GetBlockHeaders',
    data: {
      reqId: 1,
      block: 5,
github ethereumjs / ethereumjs-client / test / handler / leshandler.js View on Github external
const tape = require('tape-catch')
const td = require('testdouble')
const EventEmitter = require('events')
const Chain = td.constructor(require('../../lib/blockchain/chain'))
const Flow = td.constructor(require('../../lib/net/protocol/flowcontrol'))
const { LesHandler } = require('../../lib/handler')
const { defaultLogger } = require('../../lib/logging')
defaultLogger.silent = true

tape('[LesHandler]', t => {
  const pool = new EventEmitter()
  const chain = new Chain()
  const flow = new Flow()
  const handler = new LesHandler({ pool, chain, flow })
  const peer = { les: { send: td.func() } }
  const message = {
    name: 'GetBlockHeaders',
    data: {
      reqId: 1,
      block: 5,
      max: 100,
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Prepare.js View on Github external
beforeEach('create fakes', () => {
                FakeDeallocateStub = td.constructor(DeallocateStub);
                getStatementId = td.function();

                td.replace('../../../../lib/Protocol/Protobuf/Stubs/mysqlx_prepare_pb', { Deallocate: FakeDeallocateStub });

                Prepare = require('../../../../lib/Protocol/Protobuf/Adapters/Prepare');
            });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Expect.js View on Github external
beforeEach('create fakes', () => {
                FakeConditionStub = td.constructor(ConditionStub);

                td.replace('../../../../lib/Protocol/Protobuf/Stubs/mysqlx_expect_pb', { Open: { Condition: FakeConditionStub } });
                Expect = require('../../../../lib/Protocol/Protobuf/Adapters/Expect');
            });
github cloudflare / node-cloudflare / test / method.js View on Github external
beforeEach(done => {
    FakeClient = td.constructor(Client);
    FakeResource = td.constructor(Resource);

    done();
  });
  afterEach(done => {
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Prepare.js View on Github external
beforeEach('create fakes', () => {
                FakeExecuteStub = td.constructor(ExecuteStub);

                createPreparedStatementArgs = td.function();
                getStatementId = td.function();
                getType = td.function();

                td.replace('../../../../lib/Protocol/Protobuf/Stubs/mysqlx_prepare_pb', { Execute: FakeExecuteStub, Prepare: PrepareStub });
            });
github heroku / heroku-apps / test / commands / auth / token.js View on Github external
'use strict'

const td = require('testdouble')
const proxyquire = require('proxyquire')

const netrc = td.constructor(require('netrc-parser'))
netrc['@global'] = true

let mockMachines = {}
netrc.default = new class {
  constructor () {
    this.loadSync = () => {
      this.machines = mockMachines
    }
  }
}()

const cli = proxyquire('heroku-cli-util', {'netrc-parser': netrc})

const cmd = proxyquire('../../../src/commands/auth/token', {'heroku-cli-util': cli})
const expect = require('unexpected')