Files
mattermostest/src/main/AppVersionManager.test.js
Devin Binnie 39fbdf45c5 [MM-40406] Add more singletons, refactor main.ts into pieces, add tests and some cleanup + tests for additional coverage (#1890)
* Refactor main.ts dependencies into singleton pattern

* Split main.ts into testable pieces, some other refactoring for singleton pattern

* Unit tests for main/app/app

* Unit tests for main/app/config

* Unit tests for main/app/initialize

* Unit tests for main/app/intercom

* Unit tests for main/app/utils

* Add some more tests to get to 70% coverage

* Fix for linux

* Fix for alternate data dir paths

* Fix E2E test
2021-12-09 15:11:55 -05:00

36 lines
942 B
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import fs from 'fs';
import * as Validator from 'main/Validator';
import {AppVersionManager} from './AppVersionManager';
jest.mock('electron', () => ({
ipcMain: {
on: jest.fn(),
},
}));
jest.mock('fs', () => ({
readFileSync: jest.fn(),
writeFile: jest.fn(),
}));
jest.mock('main/Validator', () => ({
validateAppState: jest.fn(),
}));
describe('main/AppVersionManager', () => {
it('should wipe out JSON file when validation fails', () => {
fs.readFileSync.mockReturnValue('some bad JSON');
Validator.validateAppState.mockReturnValue(false);
// eslint-disable-next-line no-unused-vars
const appVersionManager = new AppVersionManager('somefilename.txt');
expect(fs.writeFile).toBeCalledWith('somefilename.txt', '{}', expect.any(Function));
});
});