Skip to content

Commit

Permalink
fail function use and removing unnecessary variable
Browse files Browse the repository at this point in the history
fail function to fail test with proper error
make code more concise
  • Loading branch information
king-11 committed Oct 6, 2020
1 parent 1fdbdd4 commit febdf71
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
6 changes: 2 additions & 4 deletions src/services/FileSystemService.real.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,13 @@ describe('FileSystemService - REAL', () => {

const files: string[] = [];

let response = true;
await fileSystemService
.flatTraverse(mockFolderPath, (meta) => {
files.push(meta.name);
return false;
})
.catch((e) => (response = e));

expect(response).toEqual(false);
.then(() => fail("promise didn't fail on false return"))
.catch((e) => expect(e).toBe(false));
});

it("throws an error if the root doesn't exist", async () => {
Expand Down
6 changes: 2 additions & 4 deletions src/services/FileSystemService.virtual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,13 @@ describe('FileSystemService - VIRTUAL', () => {

const files: string[] = [];

let response = true;
await service
.flatTraverse(mockFolderPath, (meta) => {
files.push(meta.name);
return false;
})
.catch((e) => (response = e));

expect(response).toEqual(false);
.then(() => fail("promise didn't fail on false return"))
.catch((e) => expect(e).toBe(false));
});

it("throws an error if the root doesn't exist", async () => {
Expand Down
51 changes: 24 additions & 27 deletions src/services/git/Git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,38 +224,35 @@ describe('Git', () => {
});

describe('#flatTraverse', () => {
it('returns keys of metadata of all results', async () => {
gitHubNock.getDirectory('mockFolder', ['mockFile.ts'], ['mockSubFolder']);
gitHubNock.getFile('mockFolder/mockFile.ts');
gitHubNock.getDirectory('mockFolder/mockSubFolder', ['mockSubFolderFile.txt'], []);
gitHubNock.getFile('mockFolder/mockSubFolder/mockSubFolderFile.txt');

const files: string[] = [];

await git.flatTraverse('mockFolder', (meta) => {
files.push(meta.name);
describe('#fetch dir and files', () => {
beforeEach(() => {
gitHubNock.getDirectory('mockFolder', ['mockFile.ts'], ['mockSubFolder']);
gitHubNock.getFile('mockFolder/mockFile.ts');
gitHubNock.getDirectory('mockFolder/mockSubFolder', ['mockSubFolderFile.txt'], []);
gitHubNock.getFile('mockFolder/mockSubFolder/mockSubFolderFile.txt');
});

expect(files.length).toEqual(3);
expect(files).toContain('mockFile.ts');
expect(files).toContain('mockSubFolder');
expect(files).toContain('mockSubFolderFile.txt');
});
it('returns keys of metadata of all results', async () => {
const files: string[] = [];

it('stops on false', async () => {
gitHubNock.getDirectory('mockFolder', ['mockFile.ts'], ['mockSubFolder']);
gitHubNock.getFile('mockFolder/mockFile.ts');
gitHubNock.getDirectory('mockFolder/mockSubFolder', ['mockSubFolderFile.txt'], []);
gitHubNock.getFile('mockFolder/mockSubFolder/mockSubFolderFile.txt');
await git.flatTraverse('mockFolder', (meta) => {
files.push(meta.name);
});

let response = true;
await git
.flatTraverse('mockFolder', () => {
return false;
})
.catch((e) => (response = e));
expect(files.length).toEqual(3);
expect(files).toContain('mockFile.ts');
expect(files).toContain('mockSubFolder');
expect(files).toContain('mockSubFolderFile.txt');
});

expect(response).toEqual(false);
it('stops on false', async () => {
await git
.flatTraverse('mockFolder', () => {
return false;
})
.then(() => fail("promise didn't fail"))
.catch((e) => expect(e).toBe(false));
});
});

it("throws an error if the root doesn't exist", async () => {
Expand Down

0 comments on commit febdf71

Please sign in to comment.