How to use the testdouble.callback 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 / DevAPI / Collection.js View on Github external
it('returns the document instance if it exists', () => {
            const collectionName = 'foobar';
            const documentId = 'foo';
            const criteria = `_id = :id`;
            const expected = { _id: documentId, name: 'bar' };
            const schema = 'baz';
            const session = 'qux';

            td.when(execute(td.callback(expected))).thenResolve();
            td.when(bind('id', documentId)).thenReturn({ execute });
            td.when(collectionFind(session, schema, collectionName, criteria)).thenReturn({ bind });

            collection = require('../../../lib/DevAPI/Collection');
            const instance = collection(session, schema, collectionName);

            return instance.getOne(documentId)
                .then(actual => expect(actual).to.deep.equal(expected));
        });
github mysql / mysql-connector-nodejs / test / unit / DevAPI / SqlExecute.js View on Github external
it('calls a handlers provided as an `execute` object argument', () => {
            const query = sqlExecute({ _client: { sqlStmtExecute } });
            const meta = ['bar'];

            td.when(sqlStmtExecute(td.matchers.anything(), td.callback('foo'), td.callback([meta]))).thenResolve();

            return query.execute({
                row (actual) {
                    expect(actual).to.equal('foo');
                },
                meta (actual) {
                    expect(actual).to.deep.equal([new Column(meta)]);
                }
            });
        });
github mysql / mysql-connector-nodejs / test / unit / DevAPI / CollectionFind.js View on Github external
it('wraps an operation with a cursor in a preparable instance', () => {
            const execute = td.function();
            const session = 'foo';
            const expected = ['bar'];
            const state = { warnings: expected };

            td.when(execute(td.matchers.isA(Function), td.matchers.isA(Function))).thenResolve(state);
            td.when(preparing({ session })).thenReturn({ execute });

            return collectionFind(session).execute(td.callback())
                .then(actual => expect(actual.getWarnings()).to.deep.equal(expected));
        });
    });