Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
electron-mocks
Advanced tools
Mock classes for Electron.
This library is a collection of mocked classes to replace various Electron classes and instances during testing.
npm install --save-dev electron-mocks
It's still very rough, so please help contribute to help make this functionality more robust.
Currently implemented:
All methods are implemented and should return logical values. Additionally, methods are wrapped in sinon.spy() so calls can be queried. All logical events should be emitted.
We're using TypeScript's implements
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.
Each class has most/all of its methods stubbed so that you can do things like:
function createWindow(mock = false) {
const BrowserWindowConstructor = mock ? MockBrowserWindow : BrowserWindow
const win = new BrowserWindowConstructor({
width: 840,
height: 620,
show: false,
webPreferences: {
nodeIntegration: true,
},
})
win.webContents.loadURL('https://github.com')
win.on('ready-to-show', () => {
win.show()
win.webContents.send('Hello Window!', true)
})
return win
}
describe('electron-mocks example', () => {
it('should create a BrowserWindow', async () => {
const win = createWindow(true)
assert(!win.isVisible(), 'window should not be visible until ready-to-show')
await new Promise((resolve) => win.on('ready-to-show', resolve))
expect(win).to.be.instanceOf(MockBrowserWindow)
const bounds = win.getBounds()
assert(bounds.width === 840)
assert(bounds.height === 620)
assert(win.isVisible(), 'window should be visible after ready-to-show')
sinon.assert.calledOnce(win.webContents.loadURL)
sinon.assert.calledOnce(win.webContents.send)
sinon.assert.calledWith(win.webContents.send, 'Hello Window!', true)
})
})
More/better examples in the test/examples directory.
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.
MIT
BrowserWindow
, ipcMain
, screen
, etc) with mocks for testing – although theoretically, you might be able to do this "automatically" with proxyquire.electron-mocks
with electron-mocha
to get the best of both worlds.electron-mocks
if you want.FAQs
Testing mocks for Electron
The npm package electron-mocks receives a total of 27 weekly downloads. As such, electron-mocks popularity was classified as not popular.
We found that electron-mocks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.