sequelize-mock
sequelize-mock copied to clipboard
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 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;
}
});
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.
oh.. spent almost 4 hours till I found that issue. maybe you should update docs for now :)
The same here. +1 for updating.
@PaulRBerg You better use https://www.npmjs.com/package/sequelize-redis
Does the solution from @ktsashes work for you?
I have :
Cannot read property '$useHandler' of undefined
.
Any idea?
anyone still having this issue recently? Have a mock similar to OP and both $useHandler and $queryInterface are undefined on the User.
Got the same issue here both $useHandler and $queryInterface are undefined. version 0.10.2
i am also facing the same undefined issue. any update on this?
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
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()
6 years... Is there any update? Why this bug still be there?
Are you going to fix this problem?
I have made an update on the documentation checkout my pull requests #101
I updated the documentation