Skip to content

Commit

Permalink
kick off testing with test for hasNextPages
Browse files Browse the repository at this point in the history
  • Loading branch information
esco committed Aug 30, 2014
1 parent c3a5ad5 commit 7bf92df
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ dwsync.xml
# ------------------------------------------------------------------------------
# Add your custom excludes below
# ------------------------------------------------------------------------------

coverage/
18 changes: 18 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,22 @@ if paginate.hasPreviousPages || paginate.hasNextPages(pageCount)
i.fa.fa-arrow-circle-right
```

## Running Tests

To run the test suite, first invoke the following command within the repo, installing the development dependencies:

```bash
$ npm install
```

Then run the tests:

```bash
$ npm test
```

To get the coverage:

```bash
$ npm run coverage
```
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "Node.js pagination middleware and view helpers",
"main": "./index.js",
"scripts": {
"prepublish": "npm prune"
"prepublish": "npm prune",
"test": "node_modules/mocha/bin/_mocha --reporter spec test/**/*-test.js",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha"
},
"repository": {
"type": "git",
Expand All @@ -20,5 +22,9 @@
"lodash": "^2.4.1",
"querystring": "^0.2.0"
},
"devDependencies": {}
"devDependencies": {
"chai": "^1.9.1",
"istanbul": "^0.3.0",
"mocha": "^1.21.4"
}
}
44 changes: 44 additions & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var paginate = require('../index');
var chai = require('chai');

chai.should();

describe('paginate', function(){

describe('.hasNextPages(req)', function(){

beforeEach(function(){
this.req = {query:{page:3}};
});

it('should return function', function(){
paginate.hasNextPages(this.req).should.be.a('function');
});

describe('the returned function', function(){

it('should return true when there are more pages', function(){
paginate.hasNextPages(this.req)(4).should.be.true;
});

it('should return false when there are no more pages', function(){
paginate.hasNextPages(this.req)(3).should.be.false;
});

it('should throw an error when pageCount is not a number', function(){
(function(){
paginate.hasNextPages(this.req)('');
}).should.throw(/not a number/);
});

it('should throw an error when pageCount is less than zero', function(){
(function(){
paginate.hasNextPages(this.req)('');
}).should.throw(/\> 0/);
});

})

});

});

0 comments on commit 7bf92df

Please sign in to comment.