Skip to content
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

How to multiple record mock #55

Open
ina6ra opened this issue Apr 21, 2018 · 4 comments
Open

How to multiple record mock #55

ina6ra opened this issue Apr 21, 2018 · 4 comments

Comments

@ina6ra
Copy link

ina6ra commented Apr 21, 2018

I want to make a mock with multiple records.
What kind of method is there?

The following code is the behavior image.

var UserMock = DBConnectionMock.define('users', {
  'email': 'one@example.com',
  'username': 'one'
});
var UserMock = DBConnectionMock.define('users', {
  'email': 'two@example.com',
  'username': 'two'
});
UserMock.findAll([options]).then(function(users) {
  // users test
});
@ina6ra
Copy link
Author

ina6ra commented Apr 21, 2018

I was able to solve it self. I used QueryInterface.
https://sequelize-mock.readthedocs.io/en/stable/docs/mock-queries/

UserMock = DBConnectionMock.define('users');
UserMock.$queueResult([
  UserMock.build({
    'email': 'one@example.com',
    'username': 'one'
  }),
  UserMock.build({
    'email': 'two@example.com',
    'username': 'two'
  })
]);
UserMock.findAll([options]).then(function(users) {
  // users test
});

@jsindos
Copy link

jsindos commented Sep 9, 2018

It seems like $queueResult operates for both the findAll and the findOne methods. This seems like a bad design as it means the mocking must know some detail of the implementation of the method you are testing (i.e. are you testing a method that uses findAll or findOne?).

Has there been any discussion of making $queueResult agnostic in this sense?

UserMock.$queueResult(UserMock.build())

UserMock.findAll([options]).then(function(users) {
  // users test
});

UserMock.findOne([options]).then(function(user) {
  // users test
});

@yoonwaiyan
Copy link

Hope to have better API design to mock multiple mocks, I find it very useful for my tests.

@marianyfs
Copy link

up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants