Skip to content

Commit

Permalink
100% coverage of the library
Browse files Browse the repository at this point in the history
  • Loading branch information
sibnerian committed Feb 19, 2017
1 parent 764675c commit 50ada1d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/index-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import chai from 'chai';

const proxyquire = require('proxyquire').noPreserveCache();

const renderer = { renderer: true };
const mainProcess = { mainProcess: true };
const expect = chai.expect;

describe('index', () => {
it('imports the renderer promiseIpc in the renderer environment', () => {
const promiseIpc = proxyquire('../index', {
'./renderer': renderer,
'./mainProcess': mainProcess,
'is-electron-renderer': true,
});
expect(promiseIpc).to.eql(renderer);
});

it('imports the main process promiseIpc in the mainProcess environment', () => {
const promiseIpc = proxyquire('../index', {
'./renderer': renderer,
'./mainProcess': mainProcess,
'is-electron-renderer': false,
});
expect(promiseIpc).to.eql(mainProcess);
});
});
9 changes: 9 additions & 0 deletions test/mainProcess-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ describe('mainProcess', () => {
ipcRenderer.send(route, 'replyChannel', 'dataArg1');
});

it('lets listener reject with a simple string', (done) => {
mainProcess.on(route, () => Promise.reject('goober'));
ipcRenderer.once('replyChannel', (event, status, result) => {
expect([status, result]).to.eql(['failure', 'goober']);
done();
});
ipcRenderer.send(route, 'replyChannel', 'dataArg1');
});

it('when listener throws, sends failure + error to the renderer', (done) => {
mainProcess.on(route, () => {
throw new Error('oh no');
Expand Down
9 changes: 9 additions & 0 deletions test/renderer-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ describe('renderer', () => {
mockWebContents.send(route, 'replyChannel', 'dataArg1');
});

it('lets a listener reject with a simple string', (done) => {
renderer.on(route, () => Promise.reject('goober'));
ipcMain.once('replyChannel', (event, status, result) => {
expect([status, result]).to.eql(['failure', 'goober']);
done();
});
mockWebContents.send(route, 'replyChannel', 'dataArg1');
});

it('when listener throws, sends failure + error to the main process', (done) => {
renderer.on(route, () => {
throw new Error('oh no');
Expand Down

0 comments on commit 50ada1d

Please sign in to comment.