How to use testdouble - 10 common examples

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 mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Expect.js View on Github external
it('returns a Buffer-encoded version of a Mysqlx.Expect.Open object containing the entire list of expectations', () => {
                const expectations = ['foo', 'bar'];

                td.when(createCondition('foo')).thenReturn('baz');
                td.when(createCondition('bar')).thenReturn('qux');
                td.when(FakeOpenStub.prototype.serializeBinary()).thenReturn('quux');

                const open = Expect.encodeOpen(expectations);

                // eslint-disable-next-line node/no-deprecated-api
                expect(open).to.deep.equal(new Buffer('quux'));
                expect(td.explain(FakeOpenStub.prototype.setCondList).callCount).to.equal(1);
                return expect(td.explain(FakeOpenStub.prototype.setCondList).calls[0].args[0]).to.deep.equal(['baz', 'qux']);
            });
        });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Sql.js View on Github external
it('appends placeholder values as Mysqlx.Sql.StmtExecute.args by default', () => {
                const statement = { getNamespace, getSQL };

                td.when(getNamespace()).thenReturn('foo');
                td.when(getSQL()).thenReturn('bar');
                td.when(createOperationArgs(statement)).thenReturn('baz');

                const proto = Sql.createStmtExecute(statement);

                expect(proto).to.be.an.instanceOf(FakeStmtExecuteStub);
                expect(td.explain(FakeStmtExecuteStub.prototype.setNamespace).callCount).to.equal(1);
                expect(td.explain(FakeStmtExecuteStub.prototype.setNamespace).calls[0].args[0]).to.equal('foo');
                expect(td.explain(FakeStmtExecuteStub.prototype.setStmt).callCount).to.equal(1);
                // eslint-disable-next-line node/no-deprecated-api
                expect(td.explain(FakeStmtExecuteStub.prototype.setStmt).calls[0].args[0]).to.deep.equal(new Uint8Array(new Buffer('bar')));
                expect(td.explain(FakeStmtExecuteStub.prototype.setArgsList).callCount).to.equal(1);
                expect(td.explain(FakeStmtExecuteStub.prototype.setArgsList).calls[0].args[0]).to.equal('baz');
            });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Session.js View on Github external
it('require the session to be kept open by default (without need for re-authentication)', () => {
                td.when(FakeResetStub.prototype.serializeBinary()).thenReturn('bar');

                const reset = Session.encodeReset();

                // eslint-disable-next-line node/no-deprecated-api
                expect(reset).to.deep.equal(new Buffer('bar'));
                expect(td.explain(FakeResetStub.prototype.setKeepOpen).callCount).to.equal(1);
                return expect(td.explain(FakeResetStub.prototype.setKeepOpen).calls[0].args[0]).to.equal(true);
            });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Expect.js View on Github external
it('returns a Buffer-encoded version of a Mysqlx.Expect.Open object containing the entire list of expectations', () => {
                const expectations = ['foo', 'bar'];

                td.when(createCondition('foo')).thenReturn('baz');
                td.when(createCondition('bar')).thenReturn('qux');
                td.when(FakeOpenStub.prototype.serializeBinary()).thenReturn('quux');

                const open = Expect.encodeOpen(expectations);

                // eslint-disable-next-line node/no-deprecated-api
                expect(open).to.deep.equal(new Buffer('quux'));
                expect(td.explain(FakeOpenStub.prototype.setCondList).callCount).to.equal(1);
                return expect(td.explain(FakeOpenStub.prototype.setCondList).calls[0].args[0]).to.deep.equal(['baz', 'qux']);
            });
        });
github joyent / cloudapi-gql / test / formatters.js View on Github external
beforeEach(() => {
    Handlers = TestDouble.replace('../lib/handlers', {
      network: TestDouble.func('network')
    });
    // fetch = TestDouble.func('fetch');
    request.plugins.cloudapi.fetch = () => {};
    Formatters = require('../lib/formatters');
  });
github mysql / mysql-connector-nodejs / test / unit / DevAPI / ConnectionPool.js View on Github external
.then(() => {
                    expect(td.explain(done).callCount).to.equal(2); // actice connections
                });
        });
github paypal / paypal-card-components / test / component.js View on Github external
};

    fakeTokenizationPayload = {
      payment_source: {
        card: {
          last_digits: '1111',
          card_type:   'VISA'
        }
      },
      links: []
    };
    btClientCreate = td.replace(btClient, 'create');
    contingencyFlowStart = td.replace(contingencyFlow, 'start');

    fakeHostedFieldsInstance = td.object([ 'tokenize' ]);
    td.when(fakeHostedFieldsInstance.tokenize(td.matchers.isA(Object))).thenResolve(fakeTokenizationPayload);
    hostedFieldsCreate = td.replace(hostedFields, 'create');

    fakeBtClient = {
      getConfiguration: (conf) => conf
    };

    td.when(hostedFieldsCreate(td.matchers.isA(Object))).thenResolve(fakeHostedFieldsInstance);
    td.when(btClientCreate(td.matchers.isA(Object))).thenResolve(fakeBtClient);

    const button = document.createElement('button');
    button.id = 'button';

    // $FlowFixMe
    document.body.appendChild(button);
  });
github paypal / paypal-card-components / test / component.js View on Github external
}
      },
      links: []
    };
    btClientCreate = td.replace(btClient, 'create');
    contingencyFlowStart = td.replace(contingencyFlow, 'start');

    fakeHostedFieldsInstance = td.object([ 'tokenize' ]);
    td.when(fakeHostedFieldsInstance.tokenize(td.matchers.isA(Object))).thenResolve(fakeTokenizationPayload);
    hostedFieldsCreate = td.replace(hostedFields, 'create');

    fakeBtClient = {
      getConfiguration: (conf) => conf
    };

    td.when(hostedFieldsCreate(td.matchers.isA(Object))).thenResolve(fakeHostedFieldsInstance);
    td.when(btClientCreate(td.matchers.isA(Object))).thenResolve(fakeBtClient);

    const button = document.createElement('button');
    button.id = 'button';

    // $FlowFixMe
    document.body.appendChild(button);
  });
github paypal / paypal-card-components / test / component.js View on Github external
fakeTokenizationPayload = {
      payment_source: {
        card: {
          last_digits: '1111',
          card_type:   'VISA'
        }
      },
      links: []
    };
    btClientCreate = td.replace(btClient, 'create');
    contingencyFlowStart = td.replace(contingencyFlow, 'start');

    fakeHostedFieldsInstance = td.object([ 'tokenize' ]);
    td.when(fakeHostedFieldsInstance.tokenize(td.matchers.isA(Object))).thenResolve(fakeTokenizationPayload);
    hostedFieldsCreate = td.replace(hostedFields, 'create');

    fakeBtClient = {
      getConfiguration: (conf) => conf
    };

    td.when(hostedFieldsCreate(td.matchers.isA(Object))).thenResolve(fakeHostedFieldsInstance);
    td.when(btClientCreate(td.matchers.isA(Object))).thenResolve(fakeBtClient);

    const button = document.createElement('button');
    button.id = 'button';

    // $FlowFixMe
    document.body.appendChild(button);
  });
github paypal / paypal-card-components / test / component.js View on Github external
selector: '#credit-card'
        }
      }
    };

    fakeTokenizationPayload = {
      payment_source: {
        card: {
          last_digits: '1111',
          card_type:   'VISA'
        }
      },
      links: []
    };
    btClientCreate = td.replace(btClient, 'create');
    contingencyFlowStart = td.replace(contingencyFlow, 'start');

    fakeHostedFieldsInstance = td.object([ 'tokenize' ]);
    td.when(fakeHostedFieldsInstance.tokenize(td.matchers.isA(Object))).thenResolve(fakeTokenizationPayload);
    hostedFieldsCreate = td.replace(hostedFields, 'create');

    fakeBtClient = {
      getConfiguration: (conf) => conf
    };

    td.when(hostedFieldsCreate(td.matchers.isA(Object))).thenResolve(fakeHostedFieldsInstance);
    td.when(btClientCreate(td.matchers.isA(Object))).thenResolve(fakeBtClient);

    const button = document.createElement('button');
    button.id = 'button';

    // $FlowFixMe