GithubHelp home page GithubHelp logo

Comments (3)

LoveAndCoding avatar LoveAndCoding commented on May 14, 2024

$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.

btmurrell avatar btmurrell commented on May 14, 2024

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.

LoveAndCoding avatar LoveAndCoding commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.