mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Add test for crawling functions with _.result.
This commit is contained in:
@@ -12287,6 +12287,7 @@
|
||||
var index = -1,
|
||||
length = path.length;
|
||||
|
||||
// Ensure the loop is entered when path is empty.
|
||||
if (!length) {
|
||||
object = undefined;
|
||||
length = 1;
|
||||
|
||||
21
test/test.js
21
test/test.js
@@ -18137,28 +18137,35 @@
|
||||
QUnit.module('lodash.result');
|
||||
|
||||
(function() {
|
||||
var object = {
|
||||
'a': 1,
|
||||
'b': function() { return this.a; }
|
||||
};
|
||||
var object = { 'a': 1, 'b': alwaysB };
|
||||
|
||||
QUnit.test('should invoke function values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(_.result(object, 'b'), 1);
|
||||
assert.strictEqual(_.result(object, 'b'), 'b');
|
||||
});
|
||||
|
||||
QUnit.test('should invoke default function values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var actual = _.result(object, 'c', object.b);
|
||||
assert.strictEqual(actual, 1);
|
||||
assert.strictEqual(actual, 'b');
|
||||
});
|
||||
|
||||
QUnit.test('should invoke nested function values', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var value = { 'a': lodashStable.constant({ 'b': alwaysB }) };
|
||||
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
assert.strictEqual(_.result(value, path), 'b');
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var value = { 'a': object };
|
||||
var value = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
|
||||
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
assert.strictEqual(_.result(value, path), 1);
|
||||
|
||||
Reference in New Issue
Block a user