-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var Code = require('code') | ||
var Lab = require('lab') | ||
var lab = exports.lab = Lab.script() | ||
|
||
var describe = lab.describe | ||
var it = lab.it | ||
var before = lab.before | ||
var after = lab.after | ||
var expect = Code.expect | ||
|
||
var valuesIn = require('../values-in') | ||
|
||
describe('valuesIn', function () { | ||
function Person (name) { | ||
this.name = name | ||
} | ||
Person.prototype.getName = function () { | ||
return this.name | ||
} | ||
|
||
describe('prototype', function () { | ||
before(function (done) { | ||
require('../index')() | ||
done() | ||
}) | ||
after(require('./fixtures/reset-object-prototype')) | ||
it('should get all direct enumerables valuesIn from object', function (done) { | ||
var objValues = new Person('hey').valuesIn() | ||
// assertions | ||
expect(objValues).to.deep.equal(['hey', Person.prototype.getName]) | ||
done() | ||
}) | ||
}) | ||
|
||
describe('require', function () { | ||
it('should get all direct enumerables valuesIn from object', function (done) { | ||
var objValues = valuesIn(new Person('hey')) | ||
// assertions | ||
expect(objValues).to.deep.equal(['hey', Person.prototype.getName]) | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @module object-loops/values-in | ||
*/ | ||
var keysIn = require('101/keys-in') | ||
/** | ||
* Like `keysIn`, but for values. Includes enumerable key's values from the prototype chain. | ||
* @function module:object-loops/values-in | ||
* @param {object} [obj] - object to get all (incl prototype) enumerable key's values from | ||
* @returns {array} values | ||
*/ | ||
module.exports = valuesIn | ||
|
||
function valuesIn (obj) { | ||
return keysIn(obj).map(function (key) { | ||
return obj[key] | ||
}) | ||
} |