SymphonyElectron/tests/__mocks__/electron.js
Lynn 5d3377ec02 add unit test for isInDisplayBounds and config.js (#66)
* add unit test for util: isInDisplayBounds

* add tests for config.js
2017-04-26 09:46:15 -07:00

57 lines
1.4 KiB
JavaScript

const path = require('path');
const EventEmitter = require('events');
let ipcEmitter = new EventEmitter();
// use config provided by test framework
function pathToConfigDir() {
return path.join(__dirname, '/../fixtures');
}
// simple ipc mocks for render and main process ipc using
// nodes' EventEmitter
const ipcMain = {
on: function(event, cb) {
ipcEmitter.on(event, cb);
}
}
const ipcRenderer = {
sendSync: function(event, args) {
let listeners = ipcEmitter.listeners(event);
if (listeners.length > 0) {
let listener = listeners[0];
var eventArg = {}
listener(eventArg, args);
return eventArg.returnValue;
}
return null;
},
send: function(event, args) {
var senderEvent = {
sender: {
send: function(event, arg) {
ipcEmitter.emit(event, arg);
}
}
}
ipcEmitter.emit(event, senderEvent, args);
},
on: function(eventName, cb) {
ipcEmitter.on(eventName, cb);
},
removeListener: function(eventName, cb) {
ipcEmitter.removeListener(eventName, cb);
}
}
module.exports = {
require: jest.genMockFunction(),
match: jest.genMockFunction(),
app: jest.genMockFunction(),
ipcMain: ipcMain,
ipcRenderer: ipcRenderer,
remote: jest.genMockFunction(),
dialog: jest.genMockFunction()
};