Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-mocks

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-mocks - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

31

dist/cjs/MockBrowserWindow.js

@@ -22,2 +22,12 @@ "use strict";

class MockBrowserWindow extends events_1.default {
get title() {
return this._title;
}
set title(value) {
const event = new Event('page-title-updated', { cancelable: true });
this.emit('page-title-updated', event, value);
if (event.defaultPrevented)
return;
this._title = value;
}
constructor(options = {}) {

@@ -37,3 +47,2 @@ super();

this.representedFilename = '';
this.title = '';
this.minimizable = true;

@@ -189,5 +198,2 @@ this.maximizable = true;

return;
this.emit('resize');
this.emit('resized');
Object.assign(this._bounds, bounds);
const moveEvent = new Event('will-move', { cancelable: true });

@@ -197,2 +203,4 @@ this.emit('will-move', moveEvent);

return;
Object.assign(this._bounds, bounds);
this.emit('resized');
this.emit('move');

@@ -287,9 +295,5 @@ this.emit('moved');

this.setTitle = sinon_1.default.spy((title) => {
const event = new Event('page-title-updated', { cancelable: true });
this.emit('page-title-updated', event, title);
if (event.defaultPrevented)
return;
this._title = title;
this.title = title;
});
this.getTitle = sinon_1.default.spy(() => this._title);
this.getTitle = sinon_1.default.spy(() => this.title);
this.setSheetOffset = sinon_1.default.spy();

@@ -398,2 +402,6 @@ this.flashFrame = sinon_1.default.spy();

this.setTitleBarOverlay = sinon_1.default.spy();
// new in Electron 25
this.getWindowButtonPosition = sinon_1.default.spy();
this.setWindowButtonPosition = sinon_1.default.spy();
this.setBackgroundMaterial = sinon_1.default.spy();
this._options = {};

@@ -405,2 +413,3 @@ this.webContents = new MockWebContents_1.MockWebContents(options.webPreferences);

Object.assign(this._options, options);
this.title = options.title || '';
this._backgroundColor = options.backgroundColor || this._backgroundColor;

@@ -451,2 +460,3 @@ const { x = 0, y = 0, width = 600, height = 800 } = options;

}
exports.MockBrowserWindow = MockBrowserWindow;
// static properties

@@ -458,3 +468,2 @@ MockBrowserWindow.getAllWindows = sinon_1.default.spy(() => []);

MockBrowserWindow.fromId = sinon_1.default.spy(() => null);
exports.MockBrowserWindow = MockBrowserWindow;
//# sourceMappingURL=MockBrowserWindow.js.map

@@ -9,2 +9,3 @@ "use strict";

const sinon_1 = __importDefault(require("sinon"));
const MockIpcMain_1 = require("./MockIpcMain");
let nextId = 1;

@@ -170,3 +171,3 @@ class MockWebContents extends events_1.default {

this.setImageAnimationPolicy = sinon_1.default.spy();
this.ipc = new events_1.default();
this.ipc = new MockIpcMain_1.MockIpcMain();
this.zoomFactor = options.zoomFactor || this.zoomFactor;

@@ -173,0 +174,0 @@ }

@@ -15,3 +15,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

let nextId = 1;
class MockBrowserWindow extends EventEmitter {
export class MockBrowserWindow extends EventEmitter {
get title() {
return this._title;
}
set title(value) {
const event = new Event('page-title-updated', { cancelable: true });
this.emit('page-title-updated', event, value);
if (event.defaultPrevented)
return;
this._title = value;
}
constructor(options = {}) {

@@ -31,3 +41,2 @@ super();

this.representedFilename = '';
this.title = '';
this.minimizable = true;

@@ -183,5 +192,2 @@ this.maximizable = true;

return;
this.emit('resize');
this.emit('resized');
Object.assign(this._bounds, bounds);
const moveEvent = new Event('will-move', { cancelable: true });

@@ -191,2 +197,4 @@ this.emit('will-move', moveEvent);

return;
Object.assign(this._bounds, bounds);
this.emit('resized');
this.emit('move');

@@ -281,9 +289,5 @@ this.emit('moved');

this.setTitle = sinon.spy((title) => {
const event = new Event('page-title-updated', { cancelable: true });
this.emit('page-title-updated', event, title);
if (event.defaultPrevented)
return;
this._title = title;
this.title = title;
});
this.getTitle = sinon.spy(() => this._title);
this.getTitle = sinon.spy(() => this.title);
this.setSheetOffset = sinon.spy();

@@ -392,2 +396,6 @@ this.flashFrame = sinon.spy();

this.setTitleBarOverlay = sinon.spy();
// new in Electron 25
this.getWindowButtonPosition = sinon.spy();
this.setWindowButtonPosition = sinon.spy();
this.setBackgroundMaterial = sinon.spy();
this._options = {};

@@ -399,2 +407,3 @@ this.webContents = new MockWebContents(options.webPreferences);

Object.assign(this._options, options);
this.title = options.title || '';
this._backgroundColor = options.backgroundColor || this._backgroundColor;

@@ -451,3 +460,2 @@ const { x = 0, y = 0, width = 600, height = 800 } = options;

MockBrowserWindow.fromId = sinon.spy(() => null);
export { MockBrowserWindow };
//# sourceMappingURL=MockBrowserWindow.js.map
import EventEmitter from 'events';
import sinon from 'sinon';
import { MockIpcMain } from './MockIpcMain';
let nextId = 1;

@@ -163,3 +164,3 @@ export class MockWebContents extends EventEmitter {

this.setImageAnimationPolicy = sinon.spy();
this.ipc = new EventEmitter();
this.ipc = new MockIpcMain();
this.zoomFactor = options.zoomFactor || this.zoomFactor;

@@ -166,0 +167,0 @@ }

@@ -24,3 +24,4 @@ /// <reference types="node" />

representedFilename: string;
title: string;
get title(): string;
set title(value: string);
minimizable: boolean;

@@ -210,4 +211,7 @@ maximizable: boolean;

setTitleBarOverlay: sinon.SinonSpy<any[], any>;
getWindowButtonPosition: sinon.SinonSpy<any[], any>;
setWindowButtonPosition: sinon.SinonSpy<any[], any>;
setBackgroundMaterial: sinon.SinonSpy<any[], any>;
private _options;
constructor(options?: Electron.BrowserWindowConstructorOptions);
}
{
"name": "electron-mocks",
"version": "1.1.4",
"version": "1.1.5",
"description": "Testing mocks for Electron",

@@ -36,5 +36,6 @@ "repository": {

"devDependencies": {
"@microsoft/api-documenter": "^7.22.7",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.7",
"@semantic-release/github": "^8.1.0",
"@semantic-release/npm": "^10.0.3",

@@ -45,8 +46,8 @@ "@types/chai": "^4.3.5",

"@types/sinon": "^10.0.15",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"conventional-changelog-conventionalcommits": "^5.0.0",
"electron": "^24.3.1",
"electron": "^25.0.1",
"eslint": "^8.41.0",

@@ -59,3 +60,3 @@ "eslint-config-prettier": "^8.8.0",

"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.1.3"
},

@@ -62,0 +63,0 @@ "dependencies": {

# electron-mocks
[![npm](https://img.shields.io/npm/v/electron-mocks.svg)](https://www.npmjs.com/package/electron-mocks)
[![GitHub release](https://img.shields.io/github/release/spaceagetv/electron-mocks.svg)](https://github.com/spaceagetv/electron-mocks/releases)
[![npm](https://img.shields.io/npm/dm/electron-mocks)](https://www.npmjs.com/package/electron-mocks)
[![NPM](https://img.shields.io/npm/l/electron-mocks)](/LICENSE.txt)
Mock various Electron classes for testing
Mock classes for Electron.
This library is a collection of mocked classes to replace various Electron classes and instances during testing.
This library is a collection of mocked classes to replace various Electron classes and instances during testing.
## Installation
```bash
npm install --save-dev electron-mocks
```
## Details
It's still very rough, so please help contribute to help make this functionality more robust.
Currently implemented:
- [MockBrowserWindow](src/MockBrowserWindow.ts)

@@ -19,2 +32,6 @@ - [MockWebContents](src/MockWebContents.ts)

We're using TypeScript's [`implements`](https://www.typescriptlang.org/docs/handbook/2/classes.html#implements-clauses) clauses to ensure that the mocked classes have the same public interface as the classes they're replacing. This means that you should be able to use the mocked classes in place of the real ones without any issues.
## Usage
Each class has most/all of its methods stubbed so that you can do things like:

@@ -52,1 +69,32 @@

More/better examples in the [tests/examples](tests/examples) directory.
## Contributing
Please help contribute to this project! Try to adhere to conventional commit syntax, and run `npm run lint` before submitting a PR. If you're not sure how to contribute, please open an issue and we can discuss it.
## License
MIT
## Pros/Cons and Alternatives
### Pros
- No need to spin up a real Electron instance
- No need to mock out IPC calls
- Test GUI functionality without the overhead of a real Electron instance
- Tests run fast
- All methods are already spied on, so you can easily assert that they were called
### Cons
- Not a real Electron instance, so some functionality may be missing
- Not a real Electron instance, so some functionality may be different
- Not a real Electron instance, so some functionality may be buggy
### Alternatives
- [electron-mocha](https://github.com/jprichardson/electron-mocha) - Allows you to run your tests in Electron, but you still need to mock out IPC calls and spin up a real Electron instance
- [electron-mock-ipc](https://github.com/h3poteto/electron-mock-ipc) - Mocks out Electron ipc calls. Does not rely on sinon. ipcMain and ipcRenderer communicate with one another.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc