UNPKG

kevinqdang

Version:

An npm functional programming library project

28 lines (26 loc) 1.14 kB
var expect = require('chai').expect, sinon = require('sinon'), lodown = require('../index'), customers = require('./fixtures/customers.json'); describe('lodown', function() { describe('each', function() { it('should iterate an Array, applying action to each element, index of the element, and the collection', function() { var action = sinon.spy(); lodown.each(customers, action); expect(action.callCount).to.equal(customers.length); customers.forEach(function(customer, index){ expect(action.calledWith(customer, index, customers)).to.be.true; }); }); it('should iterate an Object, applying action for each value, key of value, and Object', function() { var action = sinon.spy(); var customer = customers[0]; lodown.each(customer, action); expect(action.callCount).to.equal(Object.keys(customer).length); for(var key in customer) { expect(action.calledWith(customer[key], key, customer)).to.be.true; } }); }); });