Make app.helpers.truncate tolerant to null and undefined

This commit is contained in:
Jonne Haß 2014-12-04 16:45:00 +01:00
parent 50a3f03bfc
commit 9d5e1f604d
2 changed files with 13 additions and 0 deletions

View file

@ -1,5 +1,9 @@
(function() {
app.helpers.truncate = function(passedString, length) {
if (passedString == null || passedString == undefined) {
return passedString;
}
if (passedString.length > length) {
var lastBlank = passedString.lastIndexOf(' ', length);
var trimstring = passedString.substring(0, Math.min(length, lastBlank));

View file

@ -0,0 +1,9 @@
describe("app.helpers.truncate", function() {
it("handles null values", function() {
expect(app.helpers.truncate(null, 123)).toEqual(null);
});
it("handles undefined", function() {
expect(app.helpers.truncate(undefined, 123)).toEqual(undefined);
});
});