-
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 values = require('../values') | ||
|
||
describe('values', 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 values from object', function (done) { | ||
var objValues = new Person('hey').values() | ||
// assertions | ||
expect(objValues).to.deep.equal(['hey']) | ||
done() | ||
}) | ||
}) | ||
|
||
describe('require', function () { | ||
it('should get all direct enumerables values from object', function (done) { | ||
var objValues = values(new Person('hey')) | ||
// assertions | ||
expect(objValues).to.deep.equal(['hey']) | ||
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 | ||
*/ | ||
|
||
/** | ||
* Like `Object.keys`, but for values | ||
* @function module:object-loops/values | ||
* @param {object} [obj] - object to get hasOwnProperty enumerable key's values from | ||
* @returns {array} values | ||
*/ | ||
module.exports = values | ||
|
||
function values (obj) { | ||
return Object.keys(obj).map(function (key) { | ||
return obj[key] | ||
}) | ||
} |