question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$userHandler does not mock 'create' method

See original GitHub issue

Following example outputs “update” from console:

const dbMock = new SequelizeMock();

const User = dbMock.define('user', {
  username: 'myTestUsername',
  email: 'test@example.com',
});

User.$queryInterface.$useHandler((query, options) => {
  console.log(query);
});

User.update({ username: 'newUsername' });

and this does not output anything:

const dbMock = new SequelizeMock();

const User = dbMock.define('user', {
  username: 'myTestUsername',
  email: 'test@example.com',
});

User.$queryInterface.$useHandler((query, options) => {
  console.log(query);
});

User.create({ username: 'newUsername' });

(the difference is the method called on User model in the last line)

Funny enough, upsert works too, also the documentation is not clear about which methods are being mocked and why would ‘create’ be ignored.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:9
  • Comments:5

github_iconTop GitHub Comments

4reactions
tuqirecommented, May 10, 2018

I’m having the same problem. I do not understand why create is treated like a special case that does not use these handlers, nor adhere to model.queueFailure().

It is important to test validation errors for example.

(Also side note, the code in this repo is not up to date with the npm lib)

3reactions
alex0520commented, Jul 17, 2018

+1 Here The create function should adhere to model.queueFailure()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my class not calling my mocked methods in unit test?
Mocks are set up, but then a different instance is used. Or a mock instance is created and injected into the SUT (potentially...
Read more >
MockContext - Android Developers
A mock Context class. All methods are non-functional and throw UnsupportedOperationException . You can use this to inject other dependencies, mocks, ...
Read more >
Mockito's Mock Methods | Baeldung
In this tutorial, we'll illustrate the various uses of the standard static mock methods of the Mockito API.
Read more >
A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Using Mockito is not just a matter of adding another dependency. ... With Mockito, creating a mock is as easy as calling a...
Read more >
The Jest Object
The methods in the jest object help create mocks and let you control ... details" of the module, then you likely do not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found