👷 This calls for tests
This commit is contained in:
parent
9a2d103e7f
commit
3311e0bd67
2 changed files with 24 additions and 0 deletions
|
@ -2514,6 +2514,15 @@ describe('BrowserWindow module', () => {
|
|||
const code = `(() => "${expected}")()`
|
||||
const asyncCode = `(() => new Promise(r => setTimeout(() => r("${expected}"), 500)))()`
|
||||
const badAsyncCode = `(() => new Promise((r, e) => setTimeout(() => e("${expectedErrorMsg}"), 500)))()`
|
||||
const errorCodes = {
|
||||
Error: 'Promise.reject(new Error("Wamp-wamp"))',
|
||||
ReferenceError: 'Promise.reject(new ReferenceError("Wamp-wamp"))',
|
||||
EvalError: 'Promise.reject(new EvalError("Wamp-wamp"))',
|
||||
RangeError: 'Promise.reject(new RangeError("Wamp-wamp"))',
|
||||
SyntaxError: 'Promise.reject(new SyntaxError("Wamp-wamp"))',
|
||||
TypeError: 'Promise.reject(new TypeError("Wamp-wamp"))',
|
||||
URIError: 'Promise.reject(new URIError("Wamp-wamp"))'
|
||||
}
|
||||
|
||||
it('doesnt throw when no calback is provided', () => {
|
||||
const result = ipcRenderer.sendSync('executeJavaScript', code, false)
|
||||
|
@ -2561,6 +2570,17 @@ describe('BrowserWindow module', () => {
|
|||
done()
|
||||
})
|
||||
})
|
||||
it('rejects the returned promise with an error if an Error.prototype is thrown', async () => {
|
||||
for (const errorKey in errorCodes) {
|
||||
await new Promise((resolve) => {
|
||||
ipcRenderer.send('executeJavaScript', errorCodes[errorKey], true)
|
||||
ipcRenderer.once('executeJavaScript-promise-error-name', (event, name) => {
|
||||
assert.equal(name, errorKey)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
it('works after page load and during subframe load', (done) => {
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
// initiate a sub-frame load, then try and execute script during it
|
||||
|
|
|
@ -217,6 +217,10 @@ app.on('ready', function () {
|
|||
window.webContents.send('executeJavaScript-promise-response', result)
|
||||
}).catch((error) => {
|
||||
window.webContents.send('executeJavaScript-promise-error', error)
|
||||
|
||||
if (error && error.name) {
|
||||
window.webContents.send('executeJavaScript-promise-error-name', error.name)
|
||||
}
|
||||
})
|
||||
|
||||
if (!hasCallback) {
|
||||
|
|
Loading…
Reference in a new issue