How to use the testdouble.matchers 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 bustle / shep / test / deploy / exec-no-api.js View on Github external
test('Publishes functions', ()=> {
  td.verify(lambda.publishVersion(td.matchers.isA(Object)), { times: 2 })
})
github ktsn / vuex-class / test / bind-store.spec.ts View on Github external
it('binds mutations', () => {
    const Super = bindStore()
      .mutations(['increment'])
      .create()

    @Component
    class Test extends Super {}

    const vm = new Test({ store })
    vm.increment(123)
    td.verify(counter.mutations!.increment(
      td.matchers.anything(),
      123
    ))
  })
github ethereumjs / ethereumjs-client / test / net / peer / libp2ppeer.js View on Github external
t.test('should connect to peer', async (t) => {
    const peer = new Libp2pPeer()
    peer.bindProtocols = td.func()
    Libp2pNode.prototype.asyncStart = td.func()
    Libp2pNode.prototype.asyncDial = td.func()
    td.when(Libp2pNode.prototype.asyncStart()).thenResolve()
    td.when(Libp2pNode.prototype.asyncDial(peerInfo)).thenResolve()
    td.when(peer.bindProtocols(td.matchers.anything(), peerInfo)).thenResolve()
    peer.connect()
    peer.on('connected', () => {
      t.pass('connected')
      t.end()
    })
  })
github mysql / mysql-connector-nodejs / test / unit / Protocol / Client.js View on Github external
it('enables TLS in the connection socket', () => {
            const stream = { on };
            const client = new FakeClient(stream);
            const capabilitiesSet = td.replace(client, 'capabilitiesSet');

            td.when(capabilitiesSet({ tls: true })).thenResolve();
            td.when(connect(td.matchers.contains({ rejectUnauthorized: false, socket: stream }), td.callback())).thenReturn(stream);

            return client.enableSSL({})
                .then(actual => expect(actual).to.be.true);
        });
github philbot9 / youtube-comments-task / test / lib / youtube-api / youtube-api.js View on Github external
it('commentPage fetches comment page', done => {
    const videoId = 'videoId'
    const pageToken = 'pageToken'
    const url = buildCommentServiceUrl('action_get_comments')
    const html = '<p>comment page</p>'
    const apiResponse = { content_html: html }
    const session = {sessionToken: 'sess', commentsToken: 'comm'}

    const getSession = td.replace('../../../lib/youtube-api/session-store')
    const request = td.replace('../../../lib/utils/request')
    const Youtube = require('../../../lib/youtube-api/youtube-api')

    const requestMatcher = td.matchers.contains({
      method: 'POST',
      url: url,
      json: true,
      form: {
        page_token: pageToken,
        session_token: session.sessionToken
      }
    })

    td.when(request(requestMatcher))
      .thenReturn(Task.of(apiResponse))

    td.when(getSession(videoId))
      .thenReturn(Task.of(session))

    Youtube.commentPage(videoId, pageToken)
github ktsn / vuex-class / test / bind-store.spec.ts View on Github external
it('binds actions', () =&gt; {
    const Super = bindStore()
      .actions(['incrementAsync'])
      .create()

    @Component
    class Test extends Super {}

    const vm = new Test({ store })
    vm.incrementAsync({ delay: 100, amount: 42 })
    td.verify(counter.actions!.incrementAsync(
      td.matchers.anything(),
      { delay: 100, amount: 42 }
    ), {
      ignoreExtraArgs: true
    })
  })
github ethereumjs / ethereumjs-client / test / net / server / rlpxserver.js View on Github external
tape('[RlpxServer]', t => {
  class RlpxPeer extends EventEmitter {}
  RlpxPeer.capabilities = td.func()
  RlpxPeer.prototype.accept = td.func()
  td.replace('../../../lib/net/peer/rlpxpeer', RlpxPeer)
  class RLPx extends EventEmitter {}
  RLPx.prototype.listen = td.func()
  class DPT extends EventEmitter {}
  DPT.prototype.bind = td.func()
  td.replace('ethereumjs-devp2p', { DPT, RLPx })
  const RlpxServer = require('../../../lib/net/server/rlpxserver')
  td.when(RlpxPeer.prototype.accept(td.matchers.anything(), td.matchers.isA(RlpxServer))).thenResolve()

  t.test('should initialize correctly', async (t) => {
    const server = new RlpxServer({
      bootnodes: '10.0.0.1:1234,enode://abcd@10.0.0.2:1234',
      key: 'abcd'
    })
    t.equals(server.name, 'rlpx', 'get name')
    t.ok(server.key.equals(Buffer.from('abcd', 'hex')), 'key parse')
    t.deepEquals(server.bootnodes, [{
      ip: '10.0.0.1', port: '1234'
    }, {
      id: 'abcd', ip: '10.0.0.2', port: '1234'
    }], 'bootnodes split')
    t.end()
  })
github philbot9 / youtube-comments-task / test / lib / fetch-first-page-token.js View on Github external
<div class="comment-section-renderer">
        <h2 tabindex="0" class="comment-section-header-renderer">
          <b>Comments</b> • 22<span class="alternate-content-link"></span>
        </h2>
        <div class="yt-uix-menu comment-section-sort-menu">
        </div>
      </div>`

    const Youtube = td.replace('../../lib/youtube-api/youtube-api')
    const errorHandler = td.replace('../../lib/error-handler')
    const fetchFirstPageToken = require('../../lib/fetch-first-page-token')

    td.when(Youtube.commentsWatchFragment(videoId))
      .thenReturn(Task.of({ body: { 'watch-discussion': html }}))

    td.when(errorHandler.scraperError(td.matchers.contains({
      videoId,
      component: 'fetch-first-page-token',
      operation: 'fetch-first-page-token'
    })))
      .thenReturn(expectedError)

    fetchFirstPageToken(videoId)
      .fork(e =&gt; {
        expect(e).to.deep.equal(expectedError)
        done()
      }, res =&gt; {
        done('Task should not complete.')
      })
  })
github cloudflare / node-cloudflare / test / Client.js View on Github external
method: 'TEST',
      body: JSON.stringify({
        name: 'world',
      }),
      headers: {
        'X-Auth-Key': 'DEADBEEF',
        'X-Auth-Email': 'fake@domain.email',
      },
    };

    td.when(getter.got(), {ignoreExtraArgs: true}).thenReject();
    td
      .when(
        getter.got(
          'https://api.cloudflare.com/client/v4/example/42',
          td.matchers.contains(options)
        )
      )
      .thenResolve({body});

    const subject = new Client({
      email: 'other@domain.email',
      key: '5CA1AB1E',
    });

    const res = subject.request(
      'TEST',
      'example/42',
      {
        name: 'world',
      },
      {
github timwis / enviar / test / server / reset-password.js View on Github external
function stubDB (viewName, lookup, response) {
  const db = td.object({
    get: () => {},
    view: () => {},
    insert: () => {}
  })
  const key = 'org.couchdb.user:' + lookup
  const error = response ? null : new Error('Not found')
  const viewOpts = { keys: [lookup], include_docs: true }
  td.when(db.view('users', viewName, viewOpts)).thenCallback(error, response)
  td.when(db.get(key)).thenCallback(error, response)
  td.when(db.insert(td.matchers.isA(Object))).thenCallback()
  return db
}