Skip to content

Commit

Permalink
fixed chain missing methods, added regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Aug 15, 2016
1 parent a2dae7d commit f9e2a1f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
7 changes: 6 additions & 1 deletion chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ Chain.prototype.toJSON = function () {
extendChainPrototype()
function extendChainPrototype (hideWarnings) {
[
'every',
'inverse',
'filter',
'findKey',
'find',
'forEach',
'mapKeys',
'map',
'reduce'
'reduce',
'some'
].forEach(function (methodName) {
var filename = dasherize(methodName)
var filepath = path.join(__dirname, filename)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
},
"homepage": "https://github.com/tjmehta/object-loops",
"dependencies": {
"101": "^1.2.0",
"101": "^1.6.1",
"dasherize": "^2.0.0"
},
"devDependencies": {
"camelize": "^1.0.0",
"code": "^1.5.0",
"lab": "^6.2.0",
"nodemon": "^1.8.1",
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/all-method-names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var camelize = require('camelize')
var fs = require('fs')
var path = require('path')

var jsFile = /^(.*)[.]js$/
var ignoreFiles = /^(index|chain)[.]js$/

module.exports = fs.readdirSync(path.resolve(__dirname, '../..'))
.filter(function (filename) {
return jsFile.test(filename) && !ignoreFiles.test(filename)
})
.map(function (filename) {
return jsFile.exec(filename)[1]
})
.map(camelize)
8 changes: 8 additions & 0 deletions test/test-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var describe = lab.describe
var it = lab.it
var expect = Code.expect

var allMethodNames = require('./fixtures/all-method-names.js')
var chain = require('../chain')

describe('chain', function () {
Expand All @@ -26,6 +27,13 @@ describe('chain', function () {
expect(output).to.deep.equal({ x: 1, y: 1 })
done()
})
it('should have all methods', function (done) {
var chainable = chain({})
allMethodNames.forEach(function (name) {
expect(chainable[name]).to.be.a.function()
})
done()
})
describe('errors', function () {
it('should error if invoked w/ non-object', function (done) {
chain([]) // works w/ arrays
Expand Down
8 changes: 8 additions & 0 deletions test/test-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ var expect = Code.expect

var noop = require('101/noop')

var allMethodNames = require('./fixtures/all-method-names.js')

describe('index', function () {
describe('all methods', function () {
before(function (done) {
require('../index')()
done()
})
after(require('./fixtures/reset-object-prototype'))
it('should have all methods', function (done) {
allMethodNames.forEach(function (name) {
expect(Object[name]).to.be.a.function()
})
done()
})
it('should iterate through all the key-value pairs in the object', function (done) {
var obj = {
foo: 1,
Expand Down

0 comments on commit f9e2a1f

Please sign in to comment.