Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ctimmerm committed Oct 4, 2016
1 parent f35e5ac commit 7298eae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
npm-debug.log*
node_modules
dist
coverage
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"clean": "rimraf dist",
"test": "mocha",
"test:coverage": "istanbul cover node_modules/.bin/_mocha",
"lint": "eslint src test",
"build:umd": "webpack src/index.js dist/axios-mock-adapter.js",
"build:umd:min": "cross-env NODE_ENV=production webpack src/index.js dist/axios-mock-adapter.min.js",
Expand Down Expand Up @@ -40,7 +41,8 @@
"axios": "^0.14.0",
"chai": "^3.5.0",
"cross-env": "^3.0.0",
"eslint": "^3.6.0",
"eslint": "^3.7.1",
"istanbul": "^0.4.5",
"mocha": "^3.0.2",
"rimraf": "^2.5.2",
"webpack": "^1.13.2"
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function createErrorResponse(message, config, response) {
}

module.exports = {
find: find,
findHandler: findHandler,
purgeIfReplyOnce: purgeIfReplyOnce,
settle: settle
Expand Down
3 changes: 1 addition & 2 deletions test/basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ describe('MockAdapter basics', function() {
foo: 'bar'
});

instance.get('/foo')
return instance.get('/foo')
.then(function(response) {
expect(response.status).to.equal(200);
expect(response.data.foo).to.equal('bar');
done();
});
});

Expand Down
30 changes: 30 additions & 0 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var expect = require('chai').expect;
var find = require('../src/utils').find;

describe('utility functions', function() {
context('find', function() {
it('returns the value for which the predicate holds true', function() {
var array = [1, 2, 3];
var value = find(array, function(value) {
return value === 2;
});
expect(value).to.equal(2);
});

it('returns the first value for which the predicate holds true', function() {
var array = [{ key: 1, value: 'one' }, { key: 1, value: 'two' }];
var value = find(array, function(value) {
return value.key === 1;
});
expect(value.value).to.equal('one');
});

it('returns undefined if the value is not found', function() {
var array = [1, 2, 3];
var value = find(array, function(value) {
return value === 4;
});
expect(value).to.be.undefined;
});
});
});

0 comments on commit 7298eae

Please sign in to comment.