Skip to content

Commit 9875e98

Browse files
committed
fix: Fix "full page reload" errors in flat Karma environments
With options useIframe: false and runInParent: true, the handler to detect full page reloads was never properly removed on test completion. This fixes that error.
1 parent d98765e commit 9875e98

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

client/karma.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ function Karma (updater, socket, iframe, opener, navigator, location, document)
237237

238238
socket.emit('complete', result || {})
239239
if (this.config.clearContext) {
240+
// The onbeforeunload listener was added by the context to catch
241+
// unexpected navigations while running tests. Tests are complete, so
242+
// remove this from the top window. Fixes "full page reload" errors on
243+
// flat test environments (useIframe: false, runInParent: true).
244+
window.onbeforeunload = undefined
240245
navigateContextTo('about:blank')
241246
} else {
242247
self.updater.updateTestStatus('complete')

static/karma.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ function Karma (updater, socket, iframe, opener, navigator, location, document)
247247

248248
socket.emit('complete', result || {})
249249
if (this.config.clearContext) {
250+
// The onbeforeunload listener was added by the context to catch
251+
// unexpected navigations while running tests. Tests are complete, so
252+
// remove this from the top window. Fixes "full page reload" errors on
253+
// flat test environments (useIframe: false, runInParent: true).
254+
window.onbeforeunload = undefined
250255
navigateContextTo('about:blank')
251256
} else {
252257
self.updater.updateTestStatus('complete')

0 commit comments

Comments
 (0)