$userHandler does not mock 'create' method
See original GitHub issueFollowing 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:
- Created 6 years ago
- Reactions:9
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 tomodel.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)
+1 Here The create function should adhere to model.queueFailure()