handle undefined, add test

This commit is contained in:
Joe Fleming 2014-12-03 10:58:08 -07:00
parent d895aa5147
commit cad6504ae1
2 changed files with 6 additions and 0 deletions

View file

@ -7,6 +7,7 @@ define(function (require) {
* @returns {string}
*/
return function (text) {
if (_.isUndefined(text)) return '';
if (_.isString(text)) return text;
if (_.isObject(text)) {
if (text.query_string) return text.query_string.query;

View file

@ -182,6 +182,11 @@ define(function (require) {
});
describe('model presentation formatter', function () {
it('should present undefined as empty string', function () {
var notDefined;
expect(toUser(notDefined)).to.be('');
});
it('should present objects as strings', function () {
expect(toUser({foo: 'bar'})).to.be('{"foo":"bar"}');
});