-
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
58 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,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) | ||
} |
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 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() | ||
}) | ||
}) | ||
}) |