From 364a24fd1e051607d9cb8c8fec852c361a982c59 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Wed, 2 Apr 2014 12:43:34 +0800 Subject: [PATCH] assert.throws matches error messages properly --- test/wallet.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/wallet.js b/test/wallet.js index cfc5626..d69674e 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -153,7 +153,7 @@ describe('Wallet', function() { var wallet = new Wallet(seed, {network: 'testnet'}) assert.throws(function() { wallet.getPrivateKeyForAddress("n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X") - }, Error, 'Unknown address. Make sure the address is from the keychain and has been generated.') + }, /Unknown address. Make sure the address is from the keychain and has been generated./) }) }) @@ -248,23 +248,18 @@ describe('Wallet', function() { delete utxo[0]['hash'] delete utxo[0]['hashLittleEndian'] - var errorMessage = 'Invalid unspent output: key hash(or hashLittleEndian) is missing. ' + - 'A valid unspent output must contain outputIndex, address, value and hash(or hashLittleEndian)' - assert.throws(function() { wallet.setUnspentOutputs(utxo) - }, Error, errorMessage) + }, /Invalid unspent output: key hash\(or hashLittleEndian\) is missing/) }); ['outputIndex', 'address', 'value'].forEach(function(field){ it("throws an error when " + field + " is missing", function(){ delete utxo[0][field] - var errorMessage = 'Invalid unspent output: key ' + field + - ' is missing. A valid unspent output must contain outputIndex, address, value and hash(or hashLittleEndian)' assert.throws(function() { wallet.setUnspentOutputs(utxo) - }, Error, errorMessage) + }, new RegExp('Invalid unspent output: key ' + field + ' is missing')) }) }) }) @@ -540,7 +535,7 @@ describe('Wallet', function() { assert.throws(function() { wallet.createTx(to, value) - }, Error, 'Not enough money to send funds including transaction fee. Have: 1420000, needed: 1420001') + }, /Not enough money to send funds including transaction fee. Have: 1420000, needed: 1420001/) }) })