-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
count() method missing on Model #64
Comments
any update on this? |
If you're using jest: let mockModel;
jest.doMock("path/to/model", () => {
mockModel = dbConnectionMock.define("MyModel", myMockModel);
mockModel.count = () => 1;
return mockModel;
}); |
We are currently using sinon and we have the same problems as sinon does not allow to stub non-existent properties by design. |
So findAndCount does exist. mockModel.count = () => mockModel.findAndCount().then(res => res.count); But this feels like something that should be added in. Could model.js be extended? /**
* Executes a mock query to find instances with any provided options and return the count.
* Without any other configuration, the default behavior when no queueud query result
* is present is to return single result based on the where query in the options and
* wraps it in a promise.
*
* To turn off this behavior, the `$autoQueryFallback` option on the model should be set
* to `false`.
*
* @example
* // This is an example of the default behavior with no queued results
* // If there is a queued result or failure, that will be returned instead
* User.count({
* where: {
* email: 'myEmail@example.com',
* },
* }).then(function (count) {
* // count is an integer of how many rows were found.
* });
*
* @instance
* @method count
* @param {Object} [options] Options for the count query
* @param {Object} [options.where] Values that any automatically created Instances should have
* @return {Promise<Object>} result returned by the mock query
**/
fakeModel.prototype.count = function (options) {
var self = this;
return this.$query({
query: "count",
queryOptions: arguments,
fallbackFn: !this.options.autoQueryFallback ? null : function () {
return Promise.resolve([ self.build(options ? options.where : {}) ])
.then(function(result){
return Promise.resolve(result.length);
});
},
});
}; |
I'm using the count() method on a few of my models but it seems to be missing from the sequelize-mock API
See: http://docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-count
The text was updated successfully, but these errors were encountered: