1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

test - unit - add assertRejects to test asyncFns

This commit is contained in:
kumavis 2018-06-13 21:01:00 -07:00
parent 62586b3b6e
commit 7a001447a8
2 changed files with 23 additions and 5 deletions

View File

@ -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' ])
})
})

17
test/unit/test-utils.js Normal file
View File

@ -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)
}
}