@@ -78,24 +78,6 @@ describe('SubscribeRenderer', () => {
7878 expect ( button ) . toBeVisible ( ) ;
7979 } ) ;
8080
81- it ( 'should call subscribe and unsubscribe when pressing the send request button' , async ( ) => {
82- render ( < SubscribeRenderer name = 'ticks' auth = { 1 } reqData = { request_data } /> ) ;
83- const button = await screen . findByRole ( 'button' , { name : / S e n d R e q u e s t / i } ) ;
84- expect ( button ) . toBeVisible ( ) ;
85-
86- await userEvent . click ( button ) ;
87- expect ( mockSubscribe ) . toBeCalledTimes ( 1 ) ;
88- expect ( mockSubscribe ) . toBeCalledWith ( { ticks : 'R_50' , subscribe : 1 } ) ;
89- } ) ;
90-
91- it ( 'should call unsubscribe when pressing the clear button' , async ( ) => {
92- render ( < SubscribeRenderer name = 'ticks' auth = { 1 } reqData = { request_data } /> ) ;
93- const button = await screen . findByRole ( 'button' , { name : 'Clear' } ) ;
94- expect ( button ) . toBeVisible ( ) ;
95-
96- await userEvent . click ( button ) ;
97- } ) ;
98-
9981 it ( 'should throw an error if incorrect json is being parsed' , async ( ) => {
10082 const consoleOutput = [ ] ;
10183 const mockedError = ( output ) => consoleOutput . push ( output ) ;
@@ -110,3 +92,28 @@ describe('SubscribeRenderer', () => {
11092 ) ;
11193 } ) ;
11294} ) ;
95+
96+ it ( 'should call subscribe and unsubscribe when pressing the send request button' , async ( ) => {
97+ jest . spyOn ( React , 'useRef' ) . mockReturnValue ( {
98+ current : {
99+ unsubscribe : mockUnsubscribe ,
100+ } ,
101+ } ) ;
102+ render ( < SubscribeRenderer name = 'ticks' auth = { 1 } reqData = { request_data } /> ) ;
103+ const button = await screen . findByRole ( 'button' , { name : / S e n d R e q u e s t / i } ) ;
104+ expect ( button ) . toBeVisible ( ) ;
105+
106+ await userEvent . click ( button ) ;
107+ expect ( mockUnsubscribe ) . toBeCalledTimes ( 1 ) ;
108+ expect ( mockSubscribe ) . toBeCalledTimes ( 1 ) ;
109+ expect ( mockSubscribe ) . toBeCalledWith ( { ticks : 'R_50' , subscribe : 1 } ) ;
110+ } ) ;
111+
112+ it ( 'should call unsubscribe when pressing the clear button' , async ( ) => {
113+ render ( < SubscribeRenderer name = 'ticks' auth = { 1 } reqData = { request_data } /> ) ;
114+ const button = await screen . findByRole ( 'button' , { name : 'Clear' } ) ;
115+ expect ( button ) . toBeVisible ( ) ;
116+
117+ await userEvent . click ( button ) ;
118+ expect ( mockUnsubscribe ) . toBeCalledTimes ( 1 ) ;
119+ } ) ;
0 commit comments