Socket
Book a DemoInstallSign in
Socket

spectron-fake-dialog

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spectron-fake-dialog

Mock dialog module in your spectron's specs.

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

SpectronFakeDialog

Mock dialog module in your spectron's specs.

Installation

npm install --save-dev spectron-fake-dialog

Example

Using mocha example.

const Application = require('spectron').Application;
const electron = require('electron');
const path = require('path');
const fakeDialog = require('spectron-fake-dialog');
const assert = require('assert');

const app = new Application({ path: electron, args: [ path.join(__dirname, '.') ] });
fakeDialog.apply(app);

describe('mock showOpenDialog', function() {
  this.timeout(10000);
  beforeEach(function() {
    return app.start().then(() =>
      fakeDialog.mock([ { method: 'showOpenDialog', value: ['faked.txt'] } ])
    );;
  });

  afterEach(function() {
    return app.stop();
  });

  it('should return faked.txt', () => {
    return app.client.waitForExist('#show-open-dialog-button')
      .then(() => app.client.click('#show-open-dialog-button'))
      .then(() => app.client.getText('#return-value'))
      .then(text => assert.equal(text, JSON.stringify(['faked.txt'])));
  });
});

API

#apply(application: Application)

initialize spectronFakeDialog

#mock(params: Array<{ method: stering, value: Object }>)

NOTE: mock must call after Electron app started.

  • method: dialog module's method name. ex) showOpenDialog, showSaveDialog...
  • value: mocked method return value.

License

MIT

FAQs

Package last updated on 05 Nov 2017

Did you know?

Socket

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.

Install

Related posts