2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-06 22:40:47 +00:00
nativefier/src/options/fields/icon.test.ts
Adam Weeden 7a08a2d676
Enable TypeScript strict:true, and more typescript-eslint rules (#1223)
* Catch promise errors better

* Move subFunctions to bottom of createNewWindow

* Use parents when creating child BrowserWindow instances

* Some about:blank pages have an anchor (for some reason)

* Inject browserWindowOptions better

* Interim refactor to MainWindow object

* Split up the window functions/helpers/events some

* Further separate out window functions + tests

* Add a mock for unit testing functions that access electron

* Add unit tests for onWillPreventUnload

* Improve windowEvents tests

* Add the first test for windowHelpers

* Move WebRequest event handling to node

* insertCSS completely under test

* clearAppData completely under test

* Fix contextMenu require bug

* More tests + fixes

* Fix + add to createNewTab tests

* Convert createMainWindow back to func + work out gremlins

* Move setupWindow away from main since its shared

* Make sure contextMenu is handling promises

* Fix issues with fullscreen not working + menu refactor

* Run jest against app/dist so that we can hit app unit tests as well

* Requested PR changes

* Add strict typing; tests currently failing

* Fix failing unit tests

* Add some more eslint warnings and fixes

* More eslint fixes

* Strict typing on (still issues with the lib dir)

* Fix the package.json import/require

* Fix some funky test errors

* Warn -> Error for eslint rules

* @ts-ignore -> @ts-expect-error

* Add back the ext code I removed
2021-06-15 22:20:49 -04:00

61 lines
1.7 KiB
TypeScript

import * as log from 'loglevel';
import { icon } from './icon';
import { inferIcon } from '../../infer/inferIcon';
jest.mock('./../../infer/inferIcon');
jest.mock('loglevel');
const mockedResult = 'icon path';
const ICON_PARAMS_PROVIDED = {
packager: {
icon: './icon.png',
targetUrl: 'https://google.com',
platform: 'mac',
},
};
const ICON_PARAMS_NEEDS_INFER = {
packager: {
targetUrl: 'https://google.com',
platform: 'mac',
},
};
describe('when the icon parameter is passed', () => {
test('it should return the icon parameter', async () => {
expect(inferIcon).toHaveBeenCalledTimes(0);
await expect(icon(ICON_PARAMS_PROVIDED)).resolves.toBeUndefined();
});
});
describe('when the icon parameter is not passed', () => {
test('it should call inferIcon', async () => {
(inferIcon as jest.Mock).mockImplementationOnce(() =>
Promise.resolve(mockedResult),
);
const result = await icon(ICON_PARAMS_NEEDS_INFER);
expect(result).toBe(mockedResult);
expect(inferIcon).toHaveBeenCalledWith(
ICON_PARAMS_NEEDS_INFER.packager.targetUrl,
ICON_PARAMS_NEEDS_INFER.packager.platform,
);
});
describe('when inferIcon resolves with an error', () => {
test('it should handle the error', async () => {
(inferIcon as jest.Mock).mockImplementationOnce(() =>
Promise.reject(new Error('some error')),
);
const result = await icon(ICON_PARAMS_NEEDS_INFER);
expect(result).toBeUndefined();
expect(inferIcon).toHaveBeenCalledWith(
ICON_PARAMS_NEEDS_INFER.packager.targetUrl,
ICON_PARAMS_NEEDS_INFER.packager.platform,
);
expect(log.warn).toHaveBeenCalledTimes(1); // eslint-disable-line @typescript-eslint/unbound-method
});
});
});