Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kick off testing with test for hasNextPages #3

Merged
merged 3 commits into from
Sep 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
4 changes: 1 addition & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,4 @@ if paginate.hasPreviousPages || paginate.hasNextPages(pageCount)
a(href=paginate.href()).next
| Next 
i.fa.fa-arrow-circle-right
```


```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really include this in the readme as it isn't that important, the people who want to know test results by hand will know npm test anyways.

17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,5 +17,15 @@
"lodash": "^2.4.1",
"querystring": "^0.2.0"
},
"devDependencies": {}
}
"devDependencies": {
"chai": "^1.9.1",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocha --require should instead

"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/"
}
}
41 changes: 41 additions & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
@@ -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/);
});

})

});

});
2 changes: 2 additions & 0 deletions test/support/should.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var chai = require('chai');
chai.should();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what advantage does this have over regular should?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apis are pretty similar. This seems more like a philosophical question, especially since its a dev dependency. I wouldn't say either has a clear advantage over the other. Speed, filesize, and usability are basically the same. Chai is more active in terms of development. Consistency could be an issue since I notice most of the modules in this org use should, but I also haven't seen any of them using sinon.

I typically go with chai because of domenic's awesome https://github.com/domenic/sinon-chai. I had intended to write a few more tests that would've involved using sinon (making sure next() is being called in the middleware function) but took it out since I didn't have enough free time to do it properly. I'd prefer to keep it chai. What do you think? Have you used both?