1414 * limitations under the License.
1515 */
1616
17- import { expect } from 'chai' ;
18- import { Listener } from '../../src/infrastructure/Listener' ;
19- import { Address } from "../../src/model/account/Address" ;
20- import { deepEqual } from "assert" ;
21- import { UInt64 } from "../../src/model/UInt64" ;
22- import { timeout } from "rxjs/operators" ;
17+ import { expect } from 'chai' ;
18+ import { Listener } from '../../src/infrastructure/Listener' ;
19+ import { Address } from "../../src/model/account/Address" ;
20+ import { deepEqual } from "assert" ;
21+ import { UInt64 } from "../../src/model/UInt64" ;
22+ import { timeout } from "rxjs/operators" ;
23+ import { TransactionStatusError } from "../../src/model/transaction/TransactionStatusError" ;
2324
2425describe ( 'Listener' , ( ) => {
2526 it ( 'should createComplete a WebSocket instance given url parameter' , ( ) => {
@@ -64,17 +65,25 @@ describe('Listener', () => {
6465
6566 listener . open ( ) ;
6667
67- listener . status ( errorAddress ) . pipe ( timeout ( 2000 ) ) . subscribe ( ( transactionStatusError ) => {
68+ const reportedStatus = new Array < TransactionStatusError > ( ) ;
69+
70+ listener . status ( errorAddress ) . subscribe ( ( transactionStatusError ) => {
71+ reportedStatus . push ( transactionStatusError ) ;
72+ } , err => {
73+ done ( err ) ;
74+ } ) ;
75+
76+ listener . handleMessage ( statusInfoErrorDTO , null ) ;
77+
78+ setTimeout ( ( ) => {
79+ expect ( reportedStatus . length ) . to . be . equal ( 1 ) ;
80+ const transactionStatusError = reportedStatus [ 0 ] ;
6881 expect ( transactionStatusError . address ) . to . deep . equal ( errorAddress ) ;
6982 expect ( transactionStatusError . hash ) . to . be . equal ( statusInfoErrorDTO . hash ) ;
7083 expect ( transactionStatusError . status ) . to . be . equal ( statusInfoErrorDTO . status ) ;
7184 deepEqual ( transactionStatusError . deadline . toDTO ( ) , UInt64 . fromNumericString ( statusInfoErrorDTO . deadline ) . toDTO ( ) ) ;
7285 done ( ) ;
73- } , err => {
74- done ( 'Should have not timed out!' ) ;
75- } ) ;
76-
77- listener . handleMessage ( statusInfoErrorDTO , null ) ;
86+ } , 100 )
7887
7988
8089 } ) ;
@@ -110,15 +119,21 @@ describe('Listener', () => {
110119
111120 listener . open ( ) ;
112121
113- listener . status ( subscribedAddress ) . pipe ( timeout ( 100 ) ) . subscribe ( status => {
114- done ( 'Should have timed out!' ) ;
122+ const reportedStatus = new Array < TransactionStatusError > ( ) ;
123+
124+ listener . status ( subscribedAddress ) . subscribe ( ( transactionStatusError ) => {
125+ reportedStatus . push ( transactionStatusError ) ;
115126 } , err => {
116- expect ( err . name ) . to . be . eq ( 'TimeoutError' ) ;
117- done ( ) ;
127+ done ( err ) ;
118128 } ) ;
119129
120130 listener . handleMessage ( statusInfoErrorDTO , null ) ;
121131
132+ setTimeout ( ( ) => {
133+ expect ( reportedStatus . length ) . to . be . equal ( 0 ) ;
134+ done ( ) ;
135+ } , 100 )
136+
122137
123138 } ) ;
124139 } ) ;
@@ -127,12 +142,12 @@ describe('Listener', () => {
127142 it ( 'should reject because of wrong server url' , async ( ) => {
128143 const listener = new Listener ( 'https://notcorrecturl:0000' ) ;
129144 await listener . open ( )
130- . then ( ( result ) => {
131- throw new Error ( 'This should not be called when expecting error' ) ;
132- } )
133- . catch ( ( error ) => {
134- expect ( error . message . toString ( ) ) . not . to . be . equal ( '' ) ;
135- } ) ;
145+ . then ( ( result ) => {
146+ throw new Error ( 'This should not be called when expecting error' ) ;
147+ } )
148+ . catch ( ( error ) => {
149+ expect ( error . message . toString ( ) ) . not . to . be . equal ( '' ) ;
150+ } ) ;
136151 } ) ;
137152 } ) ;
138153} ) ;
0 commit comments