@@ -5,7 +5,6 @@ import { renderHook, waitFor } from '@testing-library/react';
55import { useContractQuery , useContractTx , useRawContract } from 'typink' ;
66import { Contract } from 'dedot/contracts' ;
77import { Psp22ContractApi } from 'contracts/psp22' ;
8-
98describe ( 'useContractQuery' , ( ) => {
109 let contractAddress : string , contract : Contract < Psp22ContractApi > ;
1110 beforeAll ( async ( ) => {
@@ -29,28 +28,37 @@ describe('useContractQuery', () => {
2928 expect ( totalSupply . current . isLoading ) . toEqual ( false ) ;
3029 } ) ;
3130
32- totalSupply . current . refresh ( ) ;
31+ const { result : balanceOf , rerender } = renderHook (
32+ ( { address } ) => useContractQuery ( { contract, args : [ address ] , fn : 'psp22BalanceOf' } ) ,
33+ {
34+ wrapper,
35+ initialProps : {
36+ address : '0x__FAKE' ,
37+ } ,
38+ } ,
39+ ) ;
3340
3441 await waitFor ( ( ) => {
35- expect ( totalSupply . current . isRefreshing ) . toEqual ( true ) ;
42+ expect ( balanceOf . current . error ) . toBeDefined ( ) ;
3643 } ) ;
3744
45+ console . log ( 'Error:' , balanceOf . current . error ) ;
46+
47+ rerender ( { address : ALICE } ) ;
48+
3849 await waitFor ( ( ) => {
39- expect ( totalSupply . current . data ) . toEqual ( BigInt ( 1e20 ) ) ;
40- expect ( totalSupply . current . isRefreshing ) . toEqual ( false ) ;
50+ expect ( balanceOf . current . data ) . toEqual ( BigInt ( 1e20 ) ) ;
4151 } ) ;
4252
43- const { result : balanceOf } = renderHook (
44- ( ) => useContractQuery ( { contract, args : [ '0x_FAKE_' ] , fn : 'psp22BalanceOf' } ) ,
45- {
46- wrapper,
47- } ,
48- ) ;
53+ balanceOf . current . refresh ( ) ;
54+
4955 await waitFor ( ( ) => {
50- expect ( balanceOf . current . error ) . toBeDefined ( ) ;
56+ expect ( balanceOf . current . isRefreshing ) . toEqual ( true ) ;
5157 } ) ;
5258
53- console . log ( 'Error:' , balanceOf . current . error ) ;
59+ await waitFor ( ( ) => {
60+ expect ( balanceOf . current . isRefreshing ) . toEqual ( false ) ;
61+ } ) ;
5462 } ) ;
5563
5664 it ( 'should dry run successfully' , async ( ) => {
0 commit comments