diff --git a/.gitignore b/.gitignore index 76c9aed..bbb91f7 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,5 @@ dwsync.xml # ------------------------------------------------------------------------------ # Add your custom excludes below # ------------------------------------------------------------------------------ + +coverage/ \ No newline at end of file diff --git a/Readme.md b/Readme.md index 737ca18..3026dcd 100644 --- a/Readme.md +++ b/Readme.md @@ -163,6 +163,4 @@ if paginate.hasPreviousPages || paginate.hasNextPages(pageCount) a(href=paginate.href()).next | Next  i.fa.fa-arrow-circle-right -``` - - +``` \ No newline at end of file diff --git a/package.json b/package.json index f15bb67..6a659f0 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,6 @@ "version": "0.0.2", "description": "Node.js pagination middleware and view helpers", "main": "./index.js", - "scripts": { - "prepublish": "npm prune" - }, "repository": { "type": "git", "url": "git://github.com/niftylettuce/express-paginate.git" @@ -20,5 +17,15 @@ "lodash": "^2.4.1", "querystring": "^0.2.0" }, - "devDependencies": {} -} + "devDependencies": { + "chai": "^1.9.1", + "istanbul": "^0.3.0", + "mocha": "^1.21.4" + }, + "scripts": { + "prepublish": "npm prune", + "test": "mocha --reporter spec --bail --check-leaks --require test/support/should test/", + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks --require test/support/should test/", + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks --require test/support/should test/" + } +} \ No newline at end of file diff --git a/test/index-test.js b/test/index-test.js new file mode 100644 index 0000000..6588f69 --- /dev/null +++ b/test/index-test.js @@ -0,0 +1,41 @@ +var paginate = require('../index'); + +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/); + }); + + }) + + }); + +}); \ No newline at end of file diff --git a/test/support/should.js b/test/support/should.js new file mode 100644 index 0000000..1ad2fe8 --- /dev/null +++ b/test/support/should.js @@ -0,0 +1,2 @@ +var chai = require('chai'); +chai.should(); \ No newline at end of file