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 authored and sthzg committed Jul 8, 2016
1 parent 7ae5dff commit c70accf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 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
5 changes: 3 additions & 2 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ function getPkgInfo(pkgName, installed, exact=true) {
});

return buildSuccess({ pkg: pkg });
}

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


Expand Down

0 comments on commit c70accf

Please sign in to comment.