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

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

Open
bentedder opened this issue Dec 15, 2017 · 14 comments
Open

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

bentedder opened this issue Dec 15, 2017 · 14 comments

Comments

@bentedder
Copy link

bentedder commented Dec 15, 2017

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;
  }
});
@LoveAndCoding
Copy link
Contributor

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.

@LoveAndCoding LoveAndCoding self-assigned this Jan 22, 2018
@idangozlan
Copy link

oh.. spent almost 4 hours till I found that issue. maybe you should update docs for now :)

@PaulRBerg
Copy link

The same here. +1 for updating.

@idangozlan
Copy link

idangozlan commented Apr 24, 2018

@scastrec
Copy link

scastrec commented Oct 29, 2018

Does the solution from @ktsashes work for you?

I have :
Cannot read property '$useHandler' of undefined.
Any idea?

@mooniker
Copy link

anyone still having this issue recently? Have a mock similar to OP and both $useHandler and $queryInterface are undefined on the User.

@BenjGue
Copy link

BenjGue commented Sep 24, 2019

Got the same issue here both $useHandler and $queryInterface are undefined.
version 0.10.2

@salauddinn
Copy link

i am also facing the same undefined issue. any update on this?

@Andrew-9
Copy link

static formatDuration(durationObj) {
function hours(h) {
if (h === undefined){
console.log(h.hours)
}
return h;
}
var hours=10;
console.log(hours(hours));
const duration = ${durationObj.hours ? (durationObj.hours + ':') : ''}${ durationObj.minutes ? durationObj.minutes : '00' }:${ (durationObj.seconds < 10) ? ('0' + durationObj.seconds) : (durationObj.seconds ? durationObj.seconds : '00') };
return duration;
}

static newMethod(hours) {
return new hours();
}
};

Please how can I fix this?

TypeError: hours is not a function

@JakeQuilty
Copy link

This is still a problem by the way. This work around worked for me #43 (comment), 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()

@mrdulin
Copy link

mrdulin commented Mar 21, 2023

6 years... Is there any update? Why this bug still be there?

@FOX521
Copy link

FOX521 commented Apr 18, 2023

Are you going to fix this problem?

@officialkevinbrian
Copy link

officialkevinbrian commented Jul 21, 2023

I have made an update on the documentation checkout my pull requests #101

@officialkevinbrian
Copy link

I updated the documentation

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

No branches or pull requests