Skip to content

Commit

Permalink
Support custom attributes (#54)
Browse files Browse the repository at this point in the history
* Support custom attributes

* remove console
  • Loading branch information
jbrumwell authored Oct 4, 2016
1 parent 2efd565 commit d6d4e6d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var Queries = function () {
key: 'track',
value: function track(query, resolve, _reject) {
if (this.tracker.tracking) {
query.mock = _extends({}, _lodash2.default.pick(query, ['method', 'sql', 'bindings', 'returning', 'transacting']), {
query.mock = _extends({}, _lodash2.default.get(query, 'mock', {}), _lodash2.default.pick(query, ['method', 'sql', 'bindings', 'returning', 'transacting']), {
response: function response(_response) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mock-knex",
"version": "0.3.5",
"version": "0.3.6",
"description": "a knex mock adapter for simulating a db during testing",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class Queries {
track(query, resolve, reject) {
if (this.tracker.tracking) {
query.mock = {
..._.get(query, 'mock', {}),
..._.pick(query, [
'method',
'sql',
Expand Down
17 changes: 17 additions & 0 deletions test/common/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ module.exports = (db) => {
db('users').select().then(_.noop);
});

it('should allow passing custom attributes to query',
(done) => {
tracker.install();

tracker.once('query', (query) => {
expect(query).to.have.property('custom');
expect(query.custom).to.be.a('boolean');
done();
});

tracker.queries.track({
mock : {
custom : true,
},
})
});

it('should return a query object with a method property',
(done) => {
tracker.once('query', (query) => {
Expand Down

0 comments on commit d6d4e6d

Please sign in to comment.