Skip to content

Commit

Permalink
added keys w/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Aug 21, 2016
1 parent d955d1f commit d5b9233
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @module object-loops/keys
*/

/**
* Equivalent to `Object.keys`. Implemented specifically for chain.
* @function module:object-loops/keys
* @param {object} [obj] - object to get hasOwnProperty enumerable keys from
* @returns {array} keys
*/
module.exports = keys

function keys (obj) {
return Object.keys(obj)
}
43 changes: 43 additions & 0 deletions test/test-keys.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 keys = require('../keys')

describe('keys', 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 keys from object', function (done) {
var objKeys = new Person('hey').keys()
// assertions
expect(objKeys).to.deep.equal(['name'])
done()
})
})

describe('require', function () {
it('should get all direct enumerables keys from object', function (done) {
var objKeys = keys(new Person('hey'))
// assertions
expect(objKeys).to.deep.equal(['name'])
done()
})
})
})

0 comments on commit d5b9233

Please sign in to comment.