lodown-micamust
v1.0.3
Published
An npm functional programming library project
Downloads
2
Readme
lodown
An npm functional programming library project
Fork this repository to your own GitHub account.
Clone your forked version of the lodown repository to a new Cloud9 workspace or locally if you prefer.
To create a
package.json
configuration file for our lodown library, from the command-line, run the command:npm init
IMPORTANT CONFIGURATION: Fill in the prompts with your own details:
When asked for test command, enter:
istanbul cover _mocha -- test/ -R spec
When asked for your git repository, you will probably be given the correct url as the default, so just select this by pressing
return
, otherwise, provide your forked GitHub repository's url.
Install the required test libraries by running the following command:
npm install i -D mocha chai sinon istanbul
Write your tests in the file
test/index.spec.js
. Check out the chai api for and be careful when asserting/expecting against complex types - you'll have to make use of the.eql
api, and not.equal
. For example:expect(lodown.filter([1, 2, 3], function(value) { return value > 2; } )).to.eql([3]);
Implement your library in the file
index.js
. Remember thatindex.js
is a Node.js module, so you must export your API using, for example:module.exports.each = each;
To run your tests, run the following command:
npm test
Check the console output for passes and failures.
Preview (Cloud9) or open the file at
coverage/lcov-report/index.html
for your coverage report. Make certain all lines of code are traversed in your tests!
Solve
Using the file at test/fixtures/customers.json
, and utilizing your lodown library, write functions that take the Array of customers and return the following:
- how many males, how many females
- oldest customer, youngest customer
- average balance
- how many customer's names begin with some letter
- how many customer's friend's names begin with some letter
- how many customers are friends
- how many customers have friends in common
- most common tags
Resources:
Docs
- https://mochajs.org
- http://chaijs.com/api/bdd/
- http://sinonjs.org/docs/#spies-api
Reading
- http://marcofranssen.nl/using-mocha-chai-sinon-to-test-node-js/
- http://stackoverflow.com/questions/19298118/what-is-the-role-of-describe-in-mocha
- http://www.vapidspace.com/coding/2014/10/29/code-coverage-metrics-with-mocha-and-istanbul/
Quick Videos
- https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-setting-up-unit-testing-with-mocha-and-chai
- https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-unit-testing-with-mocha-and-chai