Workaround: process unhandled exceptions in tests

Karma-mocha has an issue[1]: when unhandled exception is thrown right
after a test ends, the mocha doesn't executu other tests, but Karma
reports success. With the fix, the exception is rethrown correctly
after all tests and Karma fails (as expected).

[1] https://github.com/karma-runner/karma-mocha/issues/227

Change-Id: Iae031a01ead3a9004b0c290559f0b070c58a6919
diff --git a/polygerrit-ui/app/test/common-test-setup-karma.js b/polygerrit-ui/app/test/common-test-setup-karma.js
index cc934fc..2335f28 100644
--- a/polygerrit-ui/app/test/common-test-setup-karma.js
+++ b/polygerrit-ui/app/test/common-test-setup-karma.js
@@ -20,10 +20,15 @@
 self.assert = window.chai.assert;
 self.expect = window.chai.expect;
 
+// Workaround for https://github.com/karma-runner/karma-mocha/issues/227
+let unhandledError = null;
+
 window.addEventListener('error', e => {
   // For uncaught error mochajs doesn't print the full stack trace.
   // We should print it ourselves.
+  console.error('Uncaught error:');
   console.error(e.error.stack.toString());
+  unhandledError = e;
 });
 
 let originalOnBeforeUnload;
@@ -50,6 +55,9 @@
 suiteTeardown(() => {
   // This suiteTeardown() method is called only once after all tests
   window.onbeforeunload = originalOnBeforeUnload;
+  if (unhandledError) {
+    throw unhandledError;
+  }
 });
 
 // Tests can use fake timers (sandbox.useFakeTimers)