Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Mar 28, 2015
1 parent 2d75d57 commit fb0d246
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,63 @@
'use strict';

var assert = require('assert');
var npmPkgsCount = require('./index');
var npmPkgs = require('./index');

describe('npm-pkgs-count:', function() {
// body
it('should throw TypeError when `username` is not a string', function(done) {
assert.throws(function fixture() {
npmPkgs({one: 'two'});
}, /expect `username` to be string/);

assert.throws(function fixture() {
npmPkgs({one: 'two'});
}, TypeError);
done();
});


it('should throw Error when `username` is an empty string or array', function(done) {
assert.throws(function fixture() {
npmPkgs('');
}, /expect `username` to be non empty string/);

assert.throws(function fixture() {
npmPkgs('');
}, Error);

done();
});

it('should throw TypeError when `callback` is not a function', function(done) {
assert.throws(function fixture() {
npmPkgs('tunnckocore', [1, 2, 3]);
}, /expect `callback` to be/);

assert.throws(function fixture() {
npmPkgs('tunnckocore', [1, 2, 3]);
}, TypeError);
done();
});

it('should work properly when existing user given and callback', function(done) {
this.timeout(30000);

npmPkgs('tunnckocore', function _cb(err, res) {
assert.ifError(err);
assert.strictEqual(res > 90, true);
assert.strictEqual(!Array.isArray(res), true);
done();
});
});

it('should error when non existing user given', function(done) {
this.timeout(30000);

npmPkgs('fjk43hkjhhhhhhhhhhhhhhhkjgg3k4g234', function _cb(err, res) {
assert.strictEqual(err instanceof Error, true);
assert.strictEqual(err.code, 404);
assert.strictEqual(res, undefined);
done();
});
});
});

0 comments on commit fb0d246

Please sign in to comment.