Add failing spec for no callback
This commit is contained in:
parent
095e79b043
commit
6fcb784f6e
2 changed files with 22 additions and 7 deletions
|
@ -1851,7 +1851,7 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('resolves the returned promise with the result', function (done) {
|
it('resolves the returned promise with the result when a callback is specified', function (done) {
|
||||||
ipcRenderer.send('executeJavaScript', code, true)
|
ipcRenderer.send('executeJavaScript', code, true)
|
||||||
ipcRenderer.once('executeJavaScript-promise-response', function (event, result) {
|
ipcRenderer.once('executeJavaScript-promise-response', function (event, result) {
|
||||||
assert.equal(result, expected)
|
assert.equal(result, expected)
|
||||||
|
@ -1859,6 +1859,14 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('resolves the returned promise with the result when no callback is specified', function (done) {
|
||||||
|
ipcRenderer.send('executeJavaScript', code, false)
|
||||||
|
ipcRenderer.once('executeJavaScript-promise-response', function (event, result) {
|
||||||
|
assert.equal(result, expected)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('resolves the returned promise with the result if the code returns an asyncronous promise', function (done) {
|
it('resolves the returned promise with the result if the code returns an asyncronous promise', function (done) {
|
||||||
ipcRenderer.send('executeJavaScript', asyncCode, true)
|
ipcRenderer.send('executeJavaScript', asyncCode, true)
|
||||||
ipcRenderer.once('executeJavaScript-promise-response', function (event, result) {
|
ipcRenderer.once('executeJavaScript-promise-response', function (event, result) {
|
||||||
|
|
|
@ -193,16 +193,23 @@ app.on('ready', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('executeJavaScript', function (event, code, hasCallback) {
|
ipcMain.on('executeJavaScript', function (event, code, hasCallback) {
|
||||||
|
let promise
|
||||||
|
|
||||||
if (hasCallback) {
|
if (hasCallback) {
|
||||||
window.webContents.executeJavaScript(code, (result) => {
|
promise = window.webContents.executeJavaScript(code, (result) => {
|
||||||
window.webContents.send('executeJavaScript-response', result)
|
window.webContents.send('executeJavaScript-response', result)
|
||||||
}).then((result) => {
|
|
||||||
window.webContents.send('executeJavaScript-promise-response', result)
|
|
||||||
}).catch((err) => {
|
|
||||||
window.webContents.send('executeJavaScript-promise-error', err)
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
window.webContents.executeJavaScript(code)
|
promise = window.webContents.executeJavaScript(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
promise.then((result) => {
|
||||||
|
window.webContents.send('executeJavaScript-promise-response', result)
|
||||||
|
}).catch((error) => {
|
||||||
|
window.webContents.send('executeJavaScript-promise-error', error)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!hasCallback) {
|
||||||
event.returnValue = 'success'
|
event.returnValue = 'success'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue