Skip to content

Commit

Permalink
Use sinon syntax sugar for promises. (vscode-icons#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimiC authored and robertohuertasm committed Mar 11, 2018
1 parent c3c748f commit d347465
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions test/init/projectAutoDetection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ describe('AutoDetectProject: tests', function () {

it('returns a rejection when searching for a \'package.json\' fails',
function () {
const reason = 'failure';
const findFiles = sinon.stub().returns(Promise.reject(reason));
const reason = new Error('failure');
const findFiles = sinon.stub().rejects(reason);
return pad.detectProject(findFiles, userConfig)
.then(null, rej => expect(rej).to.equal(reason));
.then(null, rej => expect(rej).to.be.an.instanceOf(Error).and.have.property('message', reason.message));
});

it('detects a sub project when detection is enabled and has detected a \'package.json\' file in a sub folder',
function () {
const path1 = 'package.json';
const path2 = 'f1/f2/f3/package.json';
const findFiles = sinon.stub()
.returns(Promise.resolve([{ fsPath: path1 }, { fsPath: path2 }] as models.IVSCodeUri[]));
const findFiles = sinon.stub().resolves([{ fsPath: path1 }, { fsPath: path2 }] as models.IVSCodeUri[]);
return pad.detectProject(findFiles, userConfig)
.then(res => {
expect(res).to.be.an('array').with.length.greaterThan(0);
Expand Down Expand Up @@ -299,7 +298,7 @@ describe('AutoDetectProject: tests', function () {

it('but it has not detected a \'package.json\' file',
function () {
const findFiles = sinon.stub().returns(Promise.resolve([]));
const findFiles = sinon.stub().resolves([]);
userConfig.projectDetection.disableDetect = false;
return pad.detectProject(findFiles, userConfig)
.then(res => expect(res).to.be.an('array').with.lengthOf(0));
Expand All @@ -308,7 +307,7 @@ describe('AutoDetectProject: tests', function () {
it('and has detected a \'package.json\' file',
function () {
const path = 'package.json';
const findFiles = sinon.stub().returns(Promise.resolve([{ fsPath: path }] as models.IVSCodeUri[]));
const findFiles = sinon.stub().resolves([{ fsPath: path }] as models.IVSCodeUri[]);
userConfig.projectDetection.disableDetect = false;
return pad.detectProject(findFiles, userConfig)
.then(res => {
Expand Down

0 comments on commit d347465

Please sign in to comment.