How to use the testdouble.explain 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 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 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 mysql / mysql-connector-nodejs / test / unit / DevAPI / CollectionOrdering.js View on Github external
it('accepts multiple values as arguments', () => {
            const statement = collectionOrdering({ preparable: { forceRestart } });
            statement.setOrderings = td.function();

            statement.sort('foo', 'bar');

            expect(td.explain(statement.setOrderings).callCount).to.equal(1);
            return expect(td.explain(statement.setOrderings).calls[0].args[0]).to.deep.equal(['foo', 'bar']);
        });
github mysql / mysql-connector-nodejs / test / unit / DevAPI / TableDelete.js View on Github external
it('resets any existing query criteria expression', () => {
            const session = 'foo';
            td.when(preparing({ session })).thenReturn({ forceRestart });

            const stmt = tableDelete(session);
            const setCriteriaExpr = td.replace(stmt, 'setCriteriaExpr');

            stmt.where();

            expect(td.explain(setCriteriaExpr).callCount).to.equal(1);
            return expect(td.explain(setCriteriaExpr).calls[0].args).to.be.empty;
        });
    });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Crud.js View on Github external
it('appends placeholder assignment values of an existing criteria expression', () => {
                    const getCriteriaExpr = td.function();
                    const setCriteriaExpr = td.function();

                    const statement = { getCategory, getCriteriaExpr, getOrderings, hasBaseCriteria, setCriteriaExpr };

                    td.when(getCriteriaExpr()).thenReturn('foo');
                    td.when(createOperationArgs(statement), { ignoreExtraArgs: true }).thenReturn('bar');
                    td.when(getOrderings()).thenReturn([]);

                    FakeCrud.create(statement, { appendArgs: true, builder: 'FakeStub' });

                    expect(td.explain(setCriteriaExpr).callCount).to.equal(1);
                    expect(td.explain(setCriteriaExpr).calls[0].args[0]).to.equal('foo');
                    expect(td.explain(FakeStub.prototype.setCriteria).callCount).to.equal(1);
                    expect(td.explain(FakeStub.prototype.setCriteria).calls[0].args[0]).to.equal('foo');
                    expect(td.explain(FakeStub.prototype.setArgsList).callCount).to.equal(1);
                    return expect(td.explain(FakeStub.prototype.setArgsList).calls[0].args[0]).to.equal('bar');
                });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Crud.js View on Github external
it('uses the new limit expressions', () => {
                    const statement = { getBindings, getCategory, getOrderings, hasBaseCriteria };

                    td.when(hasBaseCriteria()).thenReturn(true);
                    td.when(getBindings()).thenReturn({});
                    td.when(createLimitExpr(statement), { ignoreExtraArgs: true }).thenReturn('foo');
                    td.when(getOrderings()).thenReturn([]);

                    FakeCrud.create(statement, { builder: 'FakeStub', useLimitExpr: true });

                    expect(td.explain(FakeStub.prototype.setLimitExpr).callCount).to.equal(1);
                    return expect(td.explain(FakeStub.prototype.setLimitExpr).calls[0].args[0]).to.equal('foo');
                });
            });
github mysql / mysql-connector-nodejs / test / unit / Protocol / Protobuf / Prepare.js View on Github external
it('creates a Mysqlx.Prepare.OneOfMessage object containing a Mysqlx.Crud.Update query', () => {
                const type = PrepareStub.OneOfMessage.Type.UPDATE;
                const statement = { getType };
                const createUpdate = td.function();

                td.replace('../../../../lib/Protocol/Protobuf/Adapters/Crud', { createUpdate });
                td.when(getType()).thenReturn(type);
                td.when(createUpdate(statement, 'foo')).thenReturn('bar');

                Prepare = require('../../../../lib/Protocol/Protobuf/Adapters/Prepare');
                Prepare.createOneOfMessage(statement, 'foo');

                expect(td.explain(FakeOneOfMessageStub.prototype.setType).callCount).to.equal(1);
                expect(td.explain(FakeOneOfMessageStub.prototype.setType).calls[0].args[0]).to.equal(type);
                expect(td.explain(FakeOneOfMessageStub.prototype.setUpdate).callCount).to.equal(1);
                return expect(td.explain(FakeOneOfMessageStub.prototype.setUpdate).calls[0].args[0]).to.equal('bar');
            });
github novemberborn / hullabaloo-config-manager / test / resolvePluginsAndPresets.js View on Github external
Object.assign([
        {
          options: {
            plugins: [
              'foo',
              'baz'
            ]
          },
          dir: path.resolve('qux')
        },
        config
      ], {overrides: []})
    ], sharedCache)
  })

  const {callCount, calls} = td.explain(resolveFrom.silent)
  t.is(callCount, 5)
  t.deepEqual(calls.shift().args, [path.resolve('bar'), 'babel-plugin-foo'])
  t.deepEqual(calls.shift().args, [path.resolve('bar'), 'babel-preset-foo'])
  t.deepEqual(calls.shift().args, [path.resolve('bar'), 'babel-plugin-baz'])
  t.deepEqual(calls.shift().args, [path.resolve('qux'), 'babel-plugin-foo'])
  t.deepEqual(calls.shift().args, [path.resolve('qux'), 'babel-plugin-baz'])
})