diff options
author | Jacob Evans <jacob@dekz.net> | 2017-11-12 01:01:27 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2017-11-12 01:01:27 +0800 |
commit | a85b1f016d96b1706dcea07aa2581a47035ba7db (patch) | |
tree | 86eae3196ff962d8b547b22afce175a174cd8935 /test | |
parent | 4ae9482d506ccdf028fcd39bbaf652bbcbef52e8 (diff) | |
download | dexon-sol-tools-a85b1f016d96b1706dcea07aa2581a47035ba7db.tar dexon-sol-tools-a85b1f016d96b1706dcea07aa2581a47035ba7db.tar.gz dexon-sol-tools-a85b1f016d96b1706dcea07aa2581a47035ba7db.tar.bz2 dexon-sol-tools-a85b1f016d96b1706dcea07aa2581a47035ba7db.tar.lz dexon-sol-tools-a85b1f016d96b1706dcea07aa2581a47035ba7db.tar.xz dexon-sol-tools-a85b1f016d96b1706dcea07aa2581a47035ba7db.tar.zst dexon-sol-tools-a85b1f016d96b1706dcea07aa2581a47035ba7db.zip |
Test case was error then unsubscribe
Diffstat (limited to 'test')
-rw-r--r-- | test/subscription_test.ts | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/test/subscription_test.ts b/test/subscription_test.ts index d328084af..9a2198e10 100644 --- a/test/subscription_test.ts +++ b/test/subscription_test.ts @@ -1,4 +1,5 @@ import 'mocha'; +import * as _ from 'lodash'; import * as chai from 'chai'; import * as Sinon from 'sinon'; import {chaiSetup} from './utils/chai_setup'; @@ -57,12 +58,15 @@ describe('SubscriptionTest', () => { let tokenAddress: string; const transferAmount = new BigNumber(42); const allowanceAmount = new BigNumber(42); + let stubs: Sinon.SinonStub[] = []; before(() => { const token = tokens[0]; tokenAddress = token.address; }); afterEach(() => { zeroEx.token.unsubscribeAll(); + _.each(stubs, s => s.restore()); + stubs = []; }); it('Should receive the Error when an error occurs', (done: DoneCallback) => { (async () => { @@ -71,20 +75,25 @@ describe('SubscriptionTest', () => { expect(logEvent).to.be.undefined(); done(); }; - Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync') - .throws("JSON RPC error") + stubs = [ + Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync') + .throws("JSON RPC error") + ] zeroEx.token.subscribe( tokenAddress, TokenEvents.Approval, indexFilterValues, callback); await zeroEx.token.setAllowanceAsync(tokenAddress, coinbase, addressWithoutFunds, allowanceAmount); })().catch(done); }); - it('Should allow unsubscribeAll to be called multiple times', (done: DoneCallback) => { + it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => { (async () => { const callback = (err: Error, logEvent: LogEvent<ApprovalContractEventArgs>) => { }; zeroEx.token.subscribe( tokenAddress, TokenEvents.Approval, indexFilterValues, callback); await zeroEx.token.setAllowanceAsync(tokenAddress, coinbase, addressWithoutFunds, allowanceAmount); - zeroEx.token.unsubscribeAll(); + stubs = [ + Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync') + .throws("JSON RPC error") + ] zeroEx.token.unsubscribeAll(); done(); })().catch(done); |