Skip to content
Permalink
Browse files

Throw exception when extending existing method

  • Loading branch information...
felixmosh committed Jul 7, 2019
1 parent edd41dc commit c35b58e7962fe8cf03566759175960a32cb45f6a
Showing with 12 additions and 0 deletions.
  1. +6 −0 src/query/builder.js
  2. +6 −0 test/unit/knex.js
@@ -1221,6 +1221,12 @@ require('../interface')(Builder);
helpers.addQueryContext(Builder);

Builder.extend = function(methodName, fn) {
if (Builder.prototype.hasOwnProperty(methodName)) {
throw new Error(
`Can't extend QueryBuilder with existing method ('${methodName}').`
);
}

assign(Builder.prototype, { [methodName]: fn });
};

@@ -495,5 +495,11 @@ describe('knex', () => {
done();
});
});

it('should throw exception when extending existing method', () => {
expect(() =>
Knex.QueryBuilder.extend('select', function(value) {})
).to.throw(`Can't extend QueryBuilder with existing method ('select')`);
});
});
});

0 comments on commit c35b58e

Please sign in to comment.
You can’t perform that action at this time.