Skip to content

Commit

Permalink
added values w/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Aug 21, 2016
1 parent 2eb98b5 commit d1c38c3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/test-values.js
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()
})
})
})
17 changes: 17 additions & 0 deletions values.js
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]
})
}

0 comments on commit d1c38c3

Please sign in to comment.