jprichardson / electron-mocha

Run Mocha tests in Electron
MIT License
345 stars 64 forks source link

Not working, or not what I think it is? #71

Closed dougluce closed 8 years ago

dougluce commented 8 years ago

This code:

it('gets ready', function(done) {
  require('electron').app.once('ready', done)
})

when run with electron-mocha gives a Mocha timeout error (Ensure the done() callback is being called in this test.).

Is this expected?

dougluce commented 8 years ago

"electron-mocha": "^2.3.0", "electron-prebuilt": "^1.2.6" should it matter.

inukshuk commented 8 years ago

Yes that's to be expected: electron-mocha runs your tests in electron's main process, or, if you pass --renderer in a renderer process. In both cases, electron-mocha is responsible for starting and initializing electron. When your tests run, electron has already been initialized, so the ready event has fired before you start listening for it.

dougluce commented 8 years ago

Cool, that makes some sense. This worked:

const {BrowserWindow} = require('electron')
it('makes a window', function (done) {
  const options = { frame: false, height: 768, width: 1024, x: 0, y: 0, show: false }
  const win = new BrowserWindow(options) 
  win.webContents.once('did-stop-loading', function () {
    win.webContents.savePage('out.html', 'HTMLOnly', done)
  })
  win.loadURL('http://cnn.com')
})