if (Meteor.isClient) {
changeProfileName = function (newName) {
if (isEmptyOrBlankString(newName)) {
throw new TypeError('Profile name is blank or empty.');
}
var currentUserId = Meteor.user()._id;
Meteor.users.update({_id: currentUserId}, {$set: {'profile.name': newName}})
};
isEmptyOrBlankString = function (string) {
if (isString(string) == false) {
throw new TypeError('Parameter is not of type string.');
}
return _.isEmpty(string.trim());
};
isString = function (string) {
return typeof string === "string";
}
}
if (!(typeof MochaWeb === 'undefined')) {
MochaWeb.testOnly(function () {
describe("Client: Helper methods", function () {
describe(" isEmptyOrBlankString Method", function () {
var string = " ";
it("has a param which is an empty or whitespace only string - returns true", function () {
chai.assert.equal(isEmptyOrBlankString(string), true);
});
it("has a param which is not a string - throw TypeError", function () {
chai.expect(isEmptyOrBlankString).to.throw(/(?:\b(?:Parameter|type|string)\b.*){3}/);
});
});
describe(" isString Method", function () {
it("has a param which is a string - return true", function () {
chai.assert.equal(isString("text"), true);
});
it("has a param which is NOT a string (number) - returns false", function () {
chai.assert.equal(isString(123), false);
});
it("has a param which is NOT a string (object) - returns false", function () {
chai.assert.equal(isString({test : 'test'}), false);
});
});
//end
});
});
}
if (!(typeof MochaWeb === 'undefined')) {
MochaWeb.testOnly(function () {
describe("Client: Profilechange methods", function () {
describe(" Login Testprofile", function () {
var loggedIn = false;
before(function () {
Meteor.loginWithPassword('testuser', 'test123');
loggedIn = Meteor.user() ? true : false ;
});
it("logged in with test account", function(){
chai.assert(Meteor.user(), true);
});
});
describe(" Change profile name (valid parameter)", function () {
before(function () {
changeProfileName('testname');
});
after(function(){
changeProfileName('testuser');
});
it("changed profile name", function(){
chai.assert.equal(Meteor.user().profile.name, 'testname');
});
});
describe(" Change profile name (invalid parameter)", function () {
it("throws error for empty or blank string param", function(){
chai.expect(changeProfileName).to.throw(/(?:\b(?:Profile|name|blank|empty)\b.*){4}/);
});
});
//end
});
})
}
This test receives a assertion error : expected [Function] to throw error matching /(?:\b(?:Profile|name|blank|empty)\b.*){4}/ but got 'Parameter is not of type string.'