Skip to content

Commit

Permalink
Added more unit tests for getPkgInfo #11
Browse files Browse the repository at this point in the history
Fixed bug for returning an error along the way
  • Loading branch information
sthzg committed Jul 7, 2016
1 parent bbd8ba0 commit 5922cad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions test/utils/utilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,21 @@ describe('getPkgInfo()', () => {
});

it('returns data from package.json', function () {
const pkg = utils.getPkgInfo('sp1dir1', this.store);
chai.equal(pkg.hasError, false);
chai.equal(pkg.pkg.version, '1.0.0');
chai.equal(pkg.pkg.name, 'sp1dir1pkg');
chai.equal(pkg.pkg.path, '/tmp/searchPath1/sp1dir1');
const pkgQ = utils.getPkgInfo('sp1dir1', this.store);
chai.equal(pkgQ.hasError, false);
chai.equal(pkgQ.pkg.version, '1.0.0');
chai.equal(pkgQ.pkg.name, 'sp1dir1pkg');
chai.equal(pkgQ.pkg.path, '/tmp/searchPath1/sp1dir1');
});

it('returns data for a matching substring with exact=fasle', function () {
const pkgQ = utils.getPkgInfo('sp1', this.store, false);
chai.equal(pkgQ.pkg.name, 'sp1dir1pkg');
});

it(`returns an error if pkg can't be found`, function () {
const pkgQ = utils.getPkgInfo('xyz', this.store);
chai.equal(pkgQ.hasError, true);
});

after(function () {
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getPkgInfo(pkgName, installed, exact=true) {
return buildSuccess({ pkg: pkg });

} else {
buildError(`${pkgName} not found in installed packages.`);
return buildError(`${pkgName} not found in installed packages.`);
}
}

Expand Down

0 comments on commit 5922cad

Please sign in to comment.