TypeError: User.$useHandler is not a function
See original GitHub issueI feel like I’m being an idiot 😃, but I’ve setup my test as close to the docs as possible, yet I’m getting an TypeError: User.$useHandler is not a function
error any time I try to run tests. I’ve dug through the code trying see if I’m using it at the right place and I’m stuck. Any help is appreciated, the library looks super useful!
var SequelizeMock = require('sequelize-mock');
var dbMock = new SequelizeMock();
var User = dbMock.define('User', {
title: 'hi',
});
User.$useHandler(function(query, queryOptions, done) {
if (query === "findOne") {
return Promise.resolve('test');
} else if (query === "destroy") {
return Promise.reject(new SequelizeMock.Error("DB down"));
} else {
// This handler can handle this query
return;
}
});
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Developers - TypeError: User.$useHandler is not a function -
I feel like I'm being an idiot :), but I've setup my test as close to the docs as possible, yet I'm getting...
Read more >TypeError: User is not a function [closed] - Stack Overflow
It's module.exports not module.export . Change that and it should work.
Read more >next-connect - npm
function onNoMatch(req, res) { res.status(404).end("page is not found... ... DO NOT use handler(req, res) directly in getServerSideProps .
Read more >Debugger.Script — Firefox Source Docs documentation - Mozilla
The body of a function—that is, all the code in the function that is not ... remove all breakpoints set in this Debugger...
Read more >useAnimatedScrollHandler | React Native Reanimated
Note that in order for the handler to be properly triggered, you should use containers that are wrapped with Animated (e.g. Animated.ScrollView and...
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
It looks like these functions are not be exposed properly on the Model prototype as we’d expect.
As a work around you can use
User.$queryInterface.$useHandler()
to get to the function for now. I’ll work on addressing this for the next patch.This is still a problem by the way. This work around worked for me https://github.com/BlinkUX/sequelize-mock/issues/43#issuecomment-359565431, but I only found it after a few hours of scrolling through the docs and my code, wondering what was wrong. If there isn’t going to be a fix soon, someone should at least update the docs temporarily.
I also had to use this workaround for
$clearHandlers()
and$clearResults()