-
Notifications
You must be signed in to change notification settings - Fork 128
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
Usage with mocha #39
Comments
Any ideas how revert is now working? Hm, wrote small workaroud for a while: var rewireReplace = function (module, replaces) {
var reverts = {};
Object.keys(replaces).forEach(function (key) {
reverts[key] = module.__get__(key);
module.__set__(key, replaces[key]);
});
return function revert () {
Object.keys(reverts).forEach(function (key) {
module.__set__(key, reverts[key]);
});
};
}; Usage: var revertRewire;
before(function () {
revertRewire = rewireReplace(modelsActions, {
'Product.findAll': fakeFindAll
});
});
after(function () {
revertRewire();
}); |
Should be fixed with 2.1.5 😀 |
Thanks. Partially :) Works: var revertRewire;
before(function () {
revertRewire = modelsActions.__set__('Product.findAll', fakeFindAll);
});
after(function () {
revertRewire();
}); Also this way it works too (I think it's a nice way to inject mocks): var revertRewire;
before(function () {
revertRewire = modelsActions.__set__({
Product: {
findAll: fakeFindAll
}
});
});
after(function () {
revertRewire();
}); And this - nope: var revertRewire;
before(function () {
revertRewire = modelsActions.__set__({
'Product.findAll': fakeFindAll
});
});
after(function () {
revertRewire();
}); So, I really like this way revertRewire = modelsActions.__set__({
Product: {
findAll: fakeFindAll
} |
jhnns
added a commit
that referenced
this issue
Feb 9, 2015
revertRewire = modelsActions.__set__({
'Product.findAll': fakeFindAll
}); This syntax was never intended to work 😁. But it is possible to implement, so I added it with v2.2.0 |
Thank you! 👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have small test case...
I want to replace some methon on global variable which is Sequelize model:
But it throws:
If I get variable and then set it back, everything works like expected.
It's a bug or I'm using it wrong?
The text was updated successfully, but these errors were encountered: