Comments (3)
$queueResult
will certainly be the way to do that going forward, however it is not in version 0.7.0. It is the major item planned for v0.8.0, but that is not quite ready yet. I have a few more issues I need to clear up before it can be released to NPM (don't want to break everyone's tests). The reason it is in the docs is that I unfortunately had an issue (now fixed) that the documentation badge in NPM was pointing to latest instead of stable, so it is showing documentation in progress. When the next version is pushed to NPM, this issue should go away.
As for the how to use it against multiple rows, the way we use it (aka the current ugly way we're fixing) is to override function calls in our tests.
var findAll;
beforeEach(function () {
findAll = UserMock.findAll;
});
afterEach(function () {
UserMock.findAll = findAll;
});
// ...
UserMock.findAll = function () {
return bluebird.resolve([
UserMock.build(), // result 1
UserMock.build(), // result 2
UserMock.build(), // result 3
]);
};
Because this is using overrides to do it, the good thing is that it will be forward-compatible. The bad thing is it is very clunky.
Obviously this is less than ideal and what we aim to fix with v0.8.0. Hopefully I'll be getting time this week to wrap that up and publish it to NPM, but unfortunately I'm not sure I can promise that.
Hope that helps,
Andrew
from sequelize-mock.
thanks for that @ktsashes. because i already have my set of data in a json resource file, in place of your repeated build lines, i started by iterating my array and calling build, then i saw you have a bulkCreate() fake, which does its own iteration. so for benefit others reading this thread, here's a little shorthand that works for me:
var findAll;
beforeEach(function () {
findAll = UserMock.findAll;
});
afterEach(function () {
UserMock.findAll = findAll;
});
//... your test iteration
var smartUsers = JSON.parse(fs.readFileSync('../resources/users.json'));
UserMock.bulkCreate(smartUsers)
.then(function(userInstances) {
UserMock.findAll = function () {
return bluebird.resolve(userInstances);
};
})
.then(function doMyTest() {
// ... assert
// ... assert
done();
});
from sequelize-mock.
Just wanted to let you know that v0.8.0 is out with a result queuing mechanism which hopefully should address this issue. You can check out the documentation for the feature if you like under Mock Queries in our documentation.
from sequelize-mock.
Related Issues (20)
- SequelizeMockEmptyQueryQueueError: No query results are queued. Unexpected query attempted to be run
- SequelizeMock as a drop-in replacement
- Feature Request - Model.findByPk HOT 1
- findOrCreate returns an Array of Instances intead of just one Instance
- jest not working with sequelize model with associations using sequelize-mock HOT 3
- jest not working with sequelize model with associations using sequelize-mock HOT 6
- Is it possible to define class level methods?
- Mock model definition is not strict
- Maintainership HOT 1
- destroy and findOne returning all instances
- Models sometimes return columns as anonymous functions instead of the actual values
- BelongsTo without 'get' prefix
- Support v5 HOT 1
- fulfilling rawQuery from mock database HOT 1
- transaction commit/rollback/LOCK/afterCommit
- Returning NaN when use sequelize.fn("count")
- Is this library compatible with models defined by Sequelize-Typescript? HOT 1
- TypeError: this.sequelize.runHooks is not a function HOT 1
- Broken link
- with mock model tableAttributes undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sequelize-mock.