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.

​​TypeError: User.$useHandler is not a function​​

See original GitHub issue

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 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:open
  • Created 6 years ago
  • Reactions:7
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
LoveAndCodingcommented, Jan 22, 2018

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.

1reaction
JakeQuiltycommented, Jul 16, 2021

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()

Read more comments on GitHub >

github_iconTop 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 >

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