mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Changes to packages/callback-hook:
- Add bindEnvironment option to Hook constructor (defaults to true).
- Add internal helper function dontBindEnvironment() which does all the
error handling stuff like Meteor.bindEnvironment() but doesn't change
the environment.
- Use dontBindEnvironment() instead of Meteor.bindEnvironment() when
bindEnvironment option is false.
- Add tests.
Changes to packages/accounts-base:
- Create hooks with { bindEnvironment: false }
- Add test for whether Meteor.userId() is available in login callbacks.
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
Tinytest.add("callback-hook - binds to registrar's env by default", function (test) {
|
|
var hook = new Hook();
|
|
var envVar = new Meteor.EnvironmentVariable;
|
|
envVar.withValue("registrar's value", function() {
|
|
hook.register(function() {
|
|
test.equal(envVar.get(), "registrar's value");
|
|
});
|
|
});
|
|
envVar.withValue("invoker's value", function() {
|
|
hook.each(function(callback) {
|
|
callback();
|
|
});
|
|
});
|
|
});
|
|
|
|
Tinytest.add("callback-hook - uses invoker's env with {bindEnvironment: false}", function (test) {
|
|
var hook = new Hook({ bindEnvironment: false });
|
|
var envVar = new Meteor.EnvironmentVariable;
|
|
envVar.withValue("registrar's value", function() {
|
|
hook.register(function() {
|
|
test.equal(envVar.get(), "invoker's value");
|
|
});
|
|
});
|
|
envVar.withValue("invoker's value", function() {
|
|
hook.each(function(callback) {
|
|
callback();
|
|
});
|
|
});
|
|
});
|
|
|
|
Tinytest.add("callback-hook - exceptions unhandled with {bindEnvironment: false}", function (test) {
|
|
var hook = new Hook({ bindEnvironment: false });
|
|
hook.register(function() {
|
|
throw new Error("Test error");
|
|
});
|
|
hook.each(function(callback) {
|
|
test.throws(callback, "Test error");
|
|
});
|
|
});
|
|
|
|
Tinytest.add("callback-hook - exceptionHandler used with {bindEnvironment: false}", function (test) {
|
|
var exToThrow = new Error("Test error");
|
|
var thrownEx = null;
|
|
var hook = new Hook({
|
|
bindEnvironment: false,
|
|
exceptionHandler: function (ex) { thrownEx = ex; }
|
|
});
|
|
hook.register(function() {
|
|
throw exToThrow;
|
|
});
|
|
hook.each(function(callback) {
|
|
callback();
|
|
});
|
|
test.equal(exToThrow, thrownEx);
|
|
});
|