Skip to content

Commit

Permalink
test: properly mock electron
Browse files Browse the repository at this point in the history
  • Loading branch information
jely2002 committed Feb 2, 2022
1 parent c75a13f commit cf7109c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ jobs:
node-version: '12'
- name: Install npm modules
run: npm install
- name: Check if electron is installed
run: cat node_modules/electron/path.txt
- name: Run Jest
run: |
npm uninstall electron
npm install electron
npm run test
run: npm run test
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
13 changes: 11 additions & 2 deletions tests/Settings.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const fs = require('fs').promises;
const os = require('os');
const { globalShortcut, clipboard } = require('electron');

jest.mock('electron');
jest.mock('electron', () => ({
clipboard: {
readText: jest.fn()
},
globalShortcut: {
unregisterAll: jest.fn(),
isRegistered: jest.fn(),
register: jest.fn(),
}
}));

const Settings = require('../modules/persistence/Settings');
const env = {version: '2.0.0-test1', app: {getPath: jest.fn().mockReturnValue('test/path')}};
Expand Down Expand Up @@ -44,7 +54,6 @@ const defaultSettings = {
describe('Load settings from file', () => {
beforeEach(() => {
jest.clearAllMocks();
jest.mock('electron');
fs.writeFile = jest.fn().mockResolvedValue('');
console.log = jest.fn().mockImplementation(() => {
});
Expand Down

0 comments on commit cf7109c

Please sign in to comment.