aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-06-14 12:01:00 +0800
committerkumavis <aaron@kumavis.me>2018-06-14 12:01:00 +0800
commit7a001447a83e80cedde1f1094b86e8dbcb9d3b90 (patch)
tree59ccd3ef7a660f2432a92f46b2fd370051fda757 /test
parent62586b3b6e1091b296002413b635467d0d698b44 (diff)
downloadtangerine-wallet-browser-7a001447a83e80cedde1f1094b86e8dbcb9d3b90.tar
tangerine-wallet-browser-7a001447a83e80cedde1f1094b86e8dbcb9d3b90.tar.gz
tangerine-wallet-browser-7a001447a83e80cedde1f1094b86e8dbcb9d3b90.tar.bz2
tangerine-wallet-browser-7a001447a83e80cedde1f1094b86e8dbcb9d3b90.tar.lz
tangerine-wallet-browser-7a001447a83e80cedde1f1094b86e8dbcb9d3b90.tar.xz
tangerine-wallet-browser-7a001447a83e80cedde1f1094b86e8dbcb9d3b90.tar.zst
tangerine-wallet-browser-7a001447a83e80cedde1f1094b86e8dbcb9d3b90.zip
test - unit - add assertRejects to test asyncFns
Diffstat (limited to 'test')
-rw-r--r--test/unit/app/account-import-strategies.spec.js11
-rw-r--r--test/unit/test-utils.js17
2 files changed, 23 insertions, 5 deletions
diff --git a/test/unit/app/account-import-strategies.spec.js b/test/unit/app/account-import-strategies.spec.js
index b709e2757..216c2f698 100644
--- a/test/unit/app/account-import-strategies.spec.js
+++ b/test/unit/app/account-import-strategies.spec.js
@@ -1,7 +1,8 @@
const assert = require('assert')
const path = require('path')
-const accountImporter = require('../../../app/scripts/account-import-strategies/index')
const ethUtil = require('ethereumjs-util')
+const accountImporter = require('../../../app/scripts/account-import-strategies/index')
+const { assertRejects } = require('../test-utils')
describe('Account Import Strategies', function () {
const privkey = '0x4cfd3e90fc78b0f86bf7524722150bb8da9c60cd532564d7ff43f5716514f553'
@@ -14,25 +15,25 @@ describe('Account Import Strategies', function () {
})
it('throws an error for empty string private key', async () => {
- assert.throws(async function() {
+ assertRejects(async function() {
await accountImporter.importAccount('Private Key', [ '' ])
}, Error, 'no empty strings')
})
it('throws an error for undefined string private key', async () => {
- assert.throws(async function () {
+ assertRejects(async function () {
await accountImporter.importAccount('Private Key', [ undefined ])
})
})
it('throws an error for undefined string private key', async () => {
- assert.throws(async function () {
+ assertRejects(async function () {
await accountImporter.importAccount('Private Key', [])
})
})
it('throws an error for invalid private key', async () => {
- assert.throws(async function () {
+ assertRejects(async function () {
await accountImporter.importAccount('Private Key', [ 'popcorn' ])
})
})
diff --git a/test/unit/test-utils.js b/test/unit/test-utils.js
new file mode 100644
index 000000000..7d0ae4d91
--- /dev/null
+++ b/test/unit/test-utils.js
@@ -0,0 +1,17 @@
+const assert = require('assert')
+
+module.exports = {
+ assertRejects,
+}
+
+// assert.rejects added in node v10
+async function assertRejects (asyncFn, regExp) {
+ let f = () => {}
+ try {
+ await asyncFn()
+ } catch (error) {
+ f = () => { throw error }
+ } finally {
+ assert.throws(f, regExp)
+ }
+}