reducer.spec.ts
1 import { Wei } from 'libs/units'; 2 import configuredStore from 'features/store'; 3 import * as actions from './actions'; 4 import * as reducer from './reducer'; 5 6 configuredStore.getState(); 7 8 describe('wallet reducer', () => { 9 describe('WALLET_SET', () => { 10 const address = '0x123'; 11 const doSomething = new Promise<string>(resolve => { 12 setTimeout(() => resolve('Success'), 10); 13 }); 14 15 const walletInstance = { 16 getAddressString: () => address, 17 signRawTransaction: () => doSomething, 18 signMessage: () => doSomething 19 }; 20 21 //@ts-ignore 22 expect(reducer.walletReducer(undefined, actions.setWallet(walletInstance))).toEqual({ 23 ...reducer.INITIAL_STATE, 24 inst: walletInstance, 25 recentAddresses: [address] 26 }); 27 }); 28 29 it('should handle WALLET_RESET', () => { 30 expect(reducer.walletReducer(undefined, actions.resetWallet())).toEqual(reducer.INITIAL_STATE); 31 }); 32 33 it('should handle WALLET_SET_BALANCE_PENDING', () => { 34 expect(reducer.walletReducer(undefined, actions.setBalancePending())).toEqual({ 35 ...reducer.INITIAL_STATE, 36 balance: { 37 ...reducer.INITIAL_STATE.balance, 38 isPending: true 39 } 40 }); 41 }); 42 43 it('should handle WALLET_SET_BALANCE_FULFILLED', () => { 44 const balance = Wei('100'); 45 expect(reducer.walletReducer(undefined, actions.setBalanceFullfilled(balance))).toEqual({ 46 ...reducer.INITIAL_STATE, 47 balance: { 48 wei: balance, 49 isPending: false 50 } 51 }); 52 }); 53 54 it('should handle WALLET_SET_BALANCE_REJECTED', () => { 55 expect(reducer.walletReducer(undefined, actions.setBalanceRejected())).toEqual({ 56 ...reducer.INITIAL_STATE, 57 balance: { 58 ...reducer.INITIAL_STATE.balance, 59 isPending: false 60 } 61 }); 62 }); 63 });