Skip to content

Commit

Permalink
Test fix: setup/teardown mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
RvanderLaan committed Jun 4, 2022
1 parent ac6c735 commit 8c27927
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/backend/Backend.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// Mocks the DBRepository file with the one defined in the __mocks__ directory
jest.mock('./DBRepository');
jest.mock('./BackupScheduler');
jest.mock('../Messaging', () => ({
RendererMessenger: {
getDefaultBackupDirectory() {
return Promise.resolve('/tmp');
},
},
}));

import Backend from './Backend';
import { ITag, ROOT_TAG_ID } from '../entities/Tag';
import { IFile } from '../entities/File';
import { OrderDirection } from './DBRepository';

const backend = new Backend();
let backend = new Backend();

const mockTag: ITag = {
id: 'tag1',
Expand Down Expand Up @@ -36,11 +44,12 @@ const mockFile: IFile = {
};

describe('Backend', () => {
beforeAll(() => {
return backend.init(true);
});

describe('Tag API', () => {
beforeEach(async () => {
backend = new Backend();
await backend.init(true);
});

it('should be able to fetch a tag after adding it', async () => {
await backend.createTag({ ...mockTag });
const dbTags = await backend.fetchTags();
Expand Down Expand Up @@ -93,8 +102,8 @@ describe('Backend', () => {
});
});

describe('mergeTags', () => {
// TODO
});
// describe('mergeTags', () => {
// TODO
// });
});
});
8 changes: 8 additions & 0 deletions src/backend/__mocks__/BackupScheduler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default class BackupSchedulerMock {
async initialize() {
// left blank intentionally
}
notifyChange() {
// left blank intentionally
}
}
2 changes: 1 addition & 1 deletion src/backend/__mocks__/DBRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IResource, ID } from '../../entities/ID';
export const dbInit = jest.fn();

/**
* A Database implementation for testing purposes
* An in-memory database implementation for testing purposes
*/
export default class InMemoryDbRepository<T extends IResource> {
/** A dictionairy containing all database entries in memory */
Expand Down

0 comments on commit 8c27927

Please sign in to comment.