aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-03-31 09:54:58 +0800
committerGitHub <noreply@github.com>2017-03-31 09:54:58 +0800
commit242ba6e0ecc8628288ca5a80c8c6183675030b1b (patch)
tree07b2b5cef8163648bc80c12476c9928f08cb4b3f /test
parent738201e8e5d829282363dda4bc0480dec7245f4a (diff)
parent47ea5452414ef4c126ff6c6ccb40615f852f8bed (diff)
downloadtangerine-wallet-browser-242ba6e0ecc8628288ca5a80c8c6183675030b1b.tar
tangerine-wallet-browser-242ba6e0ecc8628288ca5a80c8c6183675030b1b.tar.gz
tangerine-wallet-browser-242ba6e0ecc8628288ca5a80c8c6183675030b1b.tar.bz2
tangerine-wallet-browser-242ba6e0ecc8628288ca5a80c8c6183675030b1b.tar.lz
tangerine-wallet-browser-242ba6e0ecc8628288ca5a80c8c6183675030b1b.tar.xz
tangerine-wallet-browser-242ba6e0ecc8628288ca5a80c8c6183675030b1b.tar.zst
tangerine-wallet-browser-242ba6e0ecc8628288ca5a80c8c6183675030b1b.zip
Merge pull request #1298 from MetaMask/tests-fix
Test Framework Fix
Diffstat (limited to 'test')
-rw-r--r--test/helper.js51
-rw-r--r--test/unit/keyring-controller-test.js2
2 files changed, 48 insertions, 5 deletions
diff --git a/test/helper.js b/test/helper.js
index a01ea1e53..aaac7580e 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -1,11 +1,54 @@
+// disallow promises from swallowing errors
+enableFailureOnUnhandledPromiseRejection()
+
+// logging util
var log = require('loglevel')
log.setDefaultLevel(5)
+global.log = log
+//
+// polyfills
+//
+
+// dom
require('jsdom-global')()
+
+// localStorage
window.localStorage = {}
-if (!('crypto' in window)) { window.crypto = {} }
-window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
+// crypto.getRandomValues
+if (!window.crypto) window.crypto = {}
+if (!window.crypto.getRandomValues) window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
-window.log = log
-global.log = log
+
+
+function enableFailureOnUnhandledPromiseRejection() {
+ // overwrite node's promise with the stricter Bluebird promise
+ global.Promise = require('bluebird')
+
+ // modified from https://github.com/mochajs/mocha/issues/1926#issuecomment-180842722
+
+ // rethrow unhandledRejections
+ if (typeof process !== 'undefined') {
+ process.on('unhandledRejection', function (reason) {
+ throw reason
+ })
+ } else if (typeof window !== 'undefined') {
+ // 2016-02-01: No browsers support this natively, however bluebird, when.js,
+ // and probably other libraries do.
+ if (typeof window.addEventListener === 'function') {
+ window.addEventListener('unhandledrejection', function (evt) {
+ throw evt.detail.reason
+ })
+ } else {
+ var oldOHR = window.onunhandledrejection
+ window.onunhandledrejection = function (evt) {
+ if (typeof oldOHR === 'function') oldOHR.apply(this, arguments)
+ throw evt.detail.reason
+ }
+ }
+ } else if (typeof console !== 'undefined' &&
+ typeof (console.error || console.log) === 'function') {
+ (console.error || console.log)('Unhandled rejections will be ignored!')
+ }
+} \ No newline at end of file
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index aae4cdfd6..efd0a3546 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -135,7 +135,7 @@ describe('KeyringController', function() {
})
describe('#getAccounts', function() {
- it('returns the result of getAccounts for each keyring', function() {
+ it('returns the result of getAccounts for each keyring', function(done) {
keyringController.keyrings = [
{ getAccounts() { return Promise.resolve([1,2,3]) } },
{ getAccounts() { return Promise.resolve([4,5,6]) } },