SymphonyElectron/spec/downloadHandler.spec.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

jest.mock('electron-log');
jest.mock('../src/app/window-handler', () => {
2021-01-29 00:25:40 -06:00
return {
windowHandler: {
setIsAutoReload: jest.fn(() => true),
},
};
});
jest.mock('../src/app/window-utils', () => {
2021-01-29 00:25:40 -06:00
return {
windowExists: jest.fn(() => true),
};
});
describe('download handler', () => {
2021-01-29 00:25:40 -06:00
let downloadHandlerInstance;
beforeEach(() => {
jest.resetModules();
// I did it for reset module imported between tests
const { downloadHandler } = require('../src/app/download-handler');
downloadHandlerInstance = downloadHandler;
});
afterAll((done) => {
done();
});
it('should call `sendDownloadCompleted` when download succeeds', () => {
const spy: jest.SpyInstance = jest
.spyOn(downloadHandlerInstance, 'sendDownloadCompleted')
.mockImplementation(() => jest.fn());
const data: any = {
_id: '121312-123912321-1231231',
savedPath: '/abc/def/123.txt',
total: '1234556',
fileName: 'Test.txt',
};
downloadHandlerInstance.onDownloadSuccess(data);
expect(spy).toBeCalled();
});
it('should call `sendDownloadFailed` when download fails', () => {
const spy: jest.SpyInstance = jest
.spyOn(downloadHandlerInstance, 'sendDownloadFailed')
.mockImplementation(() => jest.fn());
2021-01-29 00:25:40 -06:00
downloadHandlerInstance.onDownloadFailed();
expect(spy).toBeCalled();
});
});