@@ -5,10 +5,9 @@ const token = <string>process.env.SESSION;
55const signature = < string > process . env . SIGNATURE ;
66
77describe ( 'AllErrors' , ( ) => {
8- const waitForError = ( instance : any ) => new Promise < string [ ] > ( ( resolve ) => {
9- instance . onError ( ( ...error : string [ ] ) => {
10- resolve ( error ) ;
11- } ) ;
8+ const waitForError = ( instance : any , next = ( ) => { } ) => new Promise < string [ ] > ( ( resolve ) => {
9+ instance . onError ( ( ...error : string [ ] ) => resolve ( error ) ) ;
10+ next ( ) ;
1211 } ) ;
1312
1413 it ( 'throws an error when an invalid token is set' , async ( ) => {
@@ -32,9 +31,12 @@ describe('AllErrors', () => {
3231
3332 const client = new TradingView . Client ( ) ;
3433 const chart = new client . Session . Chart ( ) ;
35- chart . setMarket ( 'XXXXX' ) ;
3634
37- const error = await waitForError ( chart ) ;
35+ const error = await waitForError (
36+ chart ,
37+ ( ) => chart . setMarket ( 'XXXXX' ) ,
38+ ) ;
39+
3840 console . log ( '=> Chart error:' , error ) ;
3941
4042 expect ( error ) . toBeDefined ( ) ;
@@ -50,10 +52,12 @@ describe('AllErrors', () => {
5052 const chart = new client . Session . Chart ( ) ;
5153 chart . setMarket ( 'BINANCE:BTCEUR' ) ;
5254
53- // @ts -expect-error
54- chart . setTimezone ( 'Nowhere/Nowhere' ) ;
55+ const error = await waitForError (
56+ chart ,
57+ // @ts -expect-error
58+ ( ) => chart . setTimezone ( 'Nowhere/Nowhere' ) ,
59+ ) ;
5560
56- const error = await waitForError ( chart ) ;
5761 console . log ( '=> Chart error:' , error ) ;
5862
5963 expect ( error ) . toBeDefined ( ) ;
@@ -63,22 +67,24 @@ describe('AllErrors', () => {
6367 expect ( error . length ) . toBe ( 3 ) ;
6468 } ) ;
6569
66- it ( 'throws an error when a custom timeframe is set without premium' , async ( ) => {
70+ it . skip ( 'throws an error when a custom timeframe is set without premium' , async ( ) => {
6771 console . log ( 'Testing "custom timeframe" error:' ) ;
6872
6973 const client = new TradingView . Client ( ) ;
7074 const chart = new client . Session . Chart ( ) ;
7175
72- chart . setMarket ( 'BINANCE:BTCEUR' , { // Set a market
73- // @ts -expect-error
74- timeframe : '20' , // Set a custom timeframe
75- /*
76- Timeframe '20' isn't available because we are
77- not logged in as a premium TradingView account
78- */
79- } ) ;
76+ const error = await waitForError (
77+ chart ,
78+ ( ) => chart . setMarket ( 'BINANCE:BTCEUR' , { // Set a market
79+ // @ts -expect-error
80+ timeframe : '20' , // Set a custom timeframe
81+ /*
82+ Timeframe '20' isn't available because we are
83+ not logged in as a premium TradingView account
84+ */
85+ } ) ,
86+ ) ;
8087
81- const error = await waitForError ( chart ) ;
8288 console . log ( '=> Chart error:' , error ) ;
8389
8490 expect ( error ) . toBeDefined ( ) ;
@@ -93,12 +99,14 @@ describe('AllErrors', () => {
9399 const client = new TradingView . Client ( ) ;
94100 const chart = new client . Session . Chart ( ) ;
95101
96- chart . setMarket ( 'BINANCE:BTCEUR' , { // Set a market
97- // @ts -expect-error
98- timeframe : 'XX' , // Set an invalid timeframe
99- } ) ;
102+ const error = await waitForError (
103+ chart ,
104+ ( ) => chart . setMarket ( 'BINANCE:BTCEUR' , { // Set a market
105+ // @ts -expect-error
106+ timeframe : 'XX' , // Set an invalid timeframe
107+ } ) ,
108+ ) ;
100109
101- const error = await waitForError ( chart ) ;
102110 console . log ( '=> Chart error:' , error ) ;
103111
104112 expect ( error ) . toBeDefined ( ) ;
@@ -114,12 +122,14 @@ describe('AllErrors', () => {
114122 const client = new TradingView . Client ( ) ;
115123 const chart = new client . Session . Chart ( ) ;
116124
117- chart . setMarket ( 'BINANCE:BTCEUR' , { // Set a market
118- timeframe : '15' ,
119- type : 'Renko' ,
120- } ) ;
125+ const error = await waitForError (
126+ chart ,
127+ ( ) => chart . setMarket ( 'BINANCE:BTCEUR' , { // Set a market
128+ timeframe : '15' ,
129+ type : 'Renko' ,
130+ } ) ,
131+ ) ;
121132
122- const error = await waitForError ( chart ) ;
123133 console . log ( '=> Chart error:' , error ) ;
124134
125135 expect ( error ) . toBeDefined ( ) ;
@@ -134,11 +144,10 @@ describe('AllErrors', () => {
134144 const client = new TradingView . Client ( ) ;
135145 const chart = new client . Session . Chart ( ) ;
136146
137- setImmediate ( ( ) => {
138- chart . setSeries ( '15' ) ;
139- } ) ;
140-
141- const error = await waitForError ( chart ) ;
147+ const error = await waitForError (
148+ chart ,
149+ ( ) => chart . setSeries ( '15' ) ,
150+ ) ;
142151 console . log ( '=> Chart error:' , error ) ;
143152
144153 expect ( error ) . toBeDefined ( ) ;
@@ -169,7 +178,7 @@ describe('AllErrors', () => {
169178
170179 const Supertrend = new chart . Study ( ST ) ;
171180
172- const error = await waitForError ( Supertrend ) as any ;
181+ const error = await waitForError ( Supertrend ) ;
173182 console . log ( '=> Study error:' , error ) ;
174183
175184 expect ( error ) . toEqual ( [
0 commit comments