add async error test

This commit is contained in:
Fabian Vogelsteller 2015-05-13 18:08:38 +02:00
parent d02a3756c9
commit 55553d78dd
1 changed files with 69 additions and 0 deletions

69
test/async.js Normal file
View File

@ -0,0 +1,69 @@
var chai = require('chai');
var assert = chai.assert;
var web3 = require('../index');
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
// use sendTransaction as dummy
var method = 'sendTransaction';
var tests = [{
result: '0xb',
formattedResult: '0xb',
call: 'eth_'+ method
}];
describe('async', function () {
tests.forEach(function (test, index) {
it('test: ' + index, function (done) {
// given
var provider = new FakeHttpProvider();
web3.setProvider(provider);
provider.injectResult(test.result);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, test.call);
assert.deepEqual(payload.params, [{}]);
});
// when
web3.eth[method]({}, function(error, result){
// then
assert.isNull(error);
assert.strictEqual(test.formattedResult, result);
done();
});
});
it('error test: ' + index, function (done) {
// given
var provider = new FakeHttpProvider();
web3.setProvider(provider);
provider.injectError({
message: test.result,
code: -32603
});
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, test.call);
assert.deepEqual(payload.params, [{}]);
});
// when
web3.eth[method]({}, function(error, result){
// then
assert.isUndefined(result);
assert.strictEqual(test.formattedResult, error.message);
done();
});
});
});
});