Skip to content

Commit

Permalink
Merge pull request jashkenas#2603 from captbaritone/move-prop-test
Browse files Browse the repository at this point in the history
Move `_.property` and `_.propertyOf` tests to objects
  • Loading branch information
captbaritone authored Oct 8, 2016
2 parents c97f687 + da23b39 commit 57cb2cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
26 changes: 26 additions & 0 deletions test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,32 @@
assert.strictEqual(_.has(void 0, 'foo'), false, 'has() returns false for undefined');
});

QUnit.test('property', function(assert) {
var stooge = {name: 'moe'};
assert.strictEqual(_.property('name')(stooge), 'moe', 'should return the property with the given name');
assert.strictEqual(_.property('name')(null), void 0, 'should return undefined for null values');
assert.strictEqual(_.property('name')(void 0), void 0, 'should return undefined for undefined values');
});

QUnit.test('propertyOf', function(assert) {
var stoogeRanks = _.propertyOf({curly: 2, moe: 1, larry: 3});
assert.strictEqual(stoogeRanks('curly'), 2, 'should return the property with the given name');
assert.strictEqual(stoogeRanks(null), void 0, 'should return undefined for null values');
assert.strictEqual(stoogeRanks(void 0), void 0, 'should return undefined for undefined values');

function MoreStooges() { this.shemp = 87; }
MoreStooges.prototype = {curly: 2, moe: 1, larry: 3};
var moreStoogeRanks = _.propertyOf(new MoreStooges());
assert.strictEqual(moreStoogeRanks('curly'), 2, 'should return properties from further up the prototype chain');

var nullPropertyOf = _.propertyOf(null);
assert.strictEqual(nullPropertyOf('curly'), void 0, 'should return undefined when obj is null');

var undefPropertyOf = _.propertyOf(void 0);
assert.strictEqual(undefPropertyOf('curly'), void 0, 'should return undefined when obj is undefined');
});


QUnit.test('isMatch', function(assert) {
var moe = {name: 'Moe Howard', hair: true};
var curly = {name: 'Curly Howard', hair: false};
Expand Down
25 changes: 0 additions & 25 deletions test/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,6 @@
assert.strictEqual(_.noop('curly', 'larry', 'moe'), void 0, 'should always return undefined');
});

QUnit.test('property', function(assert) {
var stooge = {name: 'moe'};
assert.strictEqual(_.property('name')(stooge), 'moe', 'should return the property with the given name');
assert.strictEqual(_.property('name')(null), void 0, 'should return undefined for null values');
assert.strictEqual(_.property('name')(void 0), void 0, 'should return undefined for undefined values');
});

QUnit.test('propertyOf', function(assert) {
var stoogeRanks = _.propertyOf({curly: 2, moe: 1, larry: 3});
assert.strictEqual(stoogeRanks('curly'), 2, 'should return the property with the given name');
assert.strictEqual(stoogeRanks(null), void 0, 'should return undefined for null values');
assert.strictEqual(stoogeRanks(void 0), void 0, 'should return undefined for undefined values');

function MoreStooges() { this.shemp = 87; }
MoreStooges.prototype = {curly: 2, moe: 1, larry: 3};
var moreStoogeRanks = _.propertyOf(new MoreStooges());
assert.strictEqual(moreStoogeRanks('curly'), 2, 'should return properties from further up the prototype chain');

var nullPropertyOf = _.propertyOf(null);
assert.strictEqual(nullPropertyOf('curly'), void 0, 'should return undefined when obj is null');

var undefPropertyOf = _.propertyOf(void 0);
assert.strictEqual(undefPropertyOf('curly'), void 0, 'should return undefined when obj is undefined');
});

QUnit.test('random', function(assert) {
var array = _.range(1000);
var min = Math.pow(2, 31);
Expand Down

0 comments on commit 57cb2cf

Please sign in to comment.