Mocking BrowserWindow


#1

Hi,

I’m using electron-mocha to test my electron app, and am having trouble using Sinon to stub a BrowserWindow instance to test against. My code looks like this:

Application Code:

var loadWindow = function(myWindow, apiKey) {
  myWindow.loadURL('file://' + __dirname + '/../views/auth.html')
  myWindow.webContents.on('dom-ready', function() {
    myWindow.webContents.send('apiKey', apiKey)
  })
}

Test

it('loads the window', function() {
   myWindow = sinon.createStubInstance(BrowserWindow)
   github._private.loadWindow(myWindow, "bogus-key")
   expect(myWindow.calledWith('file://' + __dirname + '/../views/auth.html')).to.eq(true)
})

When I run my tests I get:

  1) loadWindow loads the window:
     Error: Object has been destroyed
      at Error (native)
      at node_modules/sinon/lib/sinon/walk.js:28:50
      at Array.forEach (native)
      at walkInternal (node_modules/sinon/lib/sinon/walk.js:23:45)
      at walkInternal (node_modules/sinon/lib/sinon/walk.js:34:17)
      at Object.walk (node_modules/sinon/lib/sinon/walk.js:49:20)
      at Object.stub (node_modules/sinon/lib/sinon/stub.js:52:23)
      at Object.sinon.createStubInstance (node_modules/sinon/lib/sinon/util/core.js:361:26)
      at Context.<anonymous> (app/test/main/github_spec.js:74:24)

Any ideas where I might be going wrong?


#2

Even I am facing the same problem. Can someone please help with this query?

Thanks,


#3

Same problem here. Maybe method im doing causing it. When I finish with a renderer process, it sends this message from this channel.
ipcMain.on('destroy-me', (e) => { e.sender.destroy(); });