accounts: Allow specifying explicit errors in Meteor.validateNewUser

This commit is contained in:
Avital Oliver
2012-10-08 18:32:36 -07:00
parent 46fbe872d2
commit 3c3540497c
2 changed files with 15 additions and 0 deletions

View File

@@ -156,6 +156,19 @@ if (Meteor.isClient) (function () {
{invalid: true}, // should fail the new user validators
expect(function (error) {
test.equal(error.error, 403);
test.equal(
error.reason,
"User validation failed");
}));
},
logoutStep,
function(test, expect) {
Accounts.createUser({username: username3, password: password3},
{invalidAndThrowException: true}, // should fail the new user validator with a special exception
expect(function (error) {
test.equal(
error.reason,
"An exception thrown within Accounts.validateNewUser");
}));
},
// test Accounts.onCreateUser

View File

@@ -1,4 +1,6 @@
Accounts.validateNewUser(function (user) {
if (user.invalidAndThrowException)
throw new Meteor.Error(403, "An exception thrown within Accounts.validateNewUser");
return !user.invalid;
});