Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
null/undefined object defaults to empty object
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholascloud committed Mar 14, 2013
1 parent c1745c5 commit 0a995f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion l33teral.js
Expand Up @@ -42,7 +42,7 @@
* @constructor
*/
function L33teral(obj) {
this.obj = obj;
this.obj = obj || {};
}

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "l33teral",
"version": "0.7.2",
"version": "0.7.3",
"author": "Nicholas Cloud",
"description": "functions to help deal with object literals",
"keywords": ["literals", "objects", "utilities"],
Expand All @@ -16,7 +16,7 @@
"clone": "0.1.5",
"rimraf": "2.1.4"
},
"main": "./build/l33teral-0.7.2",
"main": "./build/l33teral-0.7.3",
"scripts": {
"test": "jake test --trace",
"prepublish": "jake build"
Expand Down
19 changes: 18 additions & 1 deletion test/l33teral.mocha.js
@@ -1,6 +1,7 @@
/*global describe, it*/
'use strict';
var mocha = require('mocha'),
var _ = require('underscore'),
mocha = require('mocha'),
assert = require('chai').assert,
leet = require('../l33teral'),
mockObject = require('./mock-object');
Expand All @@ -14,6 +15,22 @@ describe('L33teral', function () {
assert.equal(leetMock.obj, expected);
done();
});

it('should be empty if the constructor argument is null or undefined', function (done) {
var leetMock = leet(null);
assert.isNotNull(leetMock.obj);
assert.isTrue(_.isEmpty(leetMock.obj));

leetMock = leet(undefined);
assert.isNotNull(leetMock.obj);
assert.isTrue(_.isEmpty(leetMock.obj));

leetMock = leet();
assert.isNotNull(leetMock.obj);
assert.isTrue(_.isEmpty(leetMock.obj));

done();
});
});

describe('#tap()', function () {
Expand Down

0 comments on commit 0a995f4

Please sign in to comment.