-
Notifications
You must be signed in to change notification settings - Fork 396
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
Testing with Promise.done()
#428
Comments
I found (via debugging api doc) I can set |
Dnia 13 lutego 2015 16:40:52 CET, Christopher Chrapka notifications@github.com napisał(a):
Hi, This might end rather funky if you separate the unit tests from the main application, or do cross-module requires. The way that require() caching works is that it will store a single copy of the module in its internal module map, indexed by name. However, if two copies are installed in different locations, even if one is a symlink to the other, you may find that the when module that you're monkey-patching is not the same object instance that the "when" your app is using. That is, it may be hard to prevent a split-brain module situation and as such relying on globals is not recommended. I have had a case of duplicate "when" modules in an application personally. A better approach may be exposing an EventEmitter from your object/code and calling .emit('error') in .done()'s rejection callback. If no handler is registered, the process shall crash. Your tests can then call .on() and prevent this. |
@rkaw92 You know, mocha has something like it('should crash process', function(d){
var org_onFatalRejection = when.Promise.onFatalRejection;
after(function(){
when.Promise.onFatalRejection = org_onFatalRejection;
});
when.Promise.onFatalRejection = function(rejection){
try{
rejection.value.should.be.instanceOf(Errors.FatalError);
d();
} catch(err){
d(err);
}
};
(...)
}); |
@ohJeez, yes indeed, that is a fairly typical way to test something like For example, you could simply mock/spy/override @rkaw92's point is a good one, though, and worth expanding on a bit. In a node app, it's entirely possible for multiple copies of when.js (or any package, for that matter) to be in play (via transitive dependencies). Each copy would have it's own That's the impetus behind the new As of right now, though, there's no 'fatalRejection` event. |
@briancavalier I tried overwriting |
Crap, [Reopen and comment] button is awfully big. |
I have a scenario in which all I can do upon an error is crash the process (or pass to something that knows what to do with such things). I'm using
Promise.done()
for that. Problem is, I would like to unit test if in that scenario.done()
is called, but without crashing unit test process. So before hacking around in prototypes I would like to ask:Is there (or should be introduced) a "supported" way to do such testing?
The text was updated successfully, but these errors were encountered: