Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 8947756

Browse files
committed
chore: test cases
1 parent 8ecc698 commit 8947756

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

src/features/Apiexplorer/SubscribeRenderer/__tests__/SubscribeRenderer.test.tsx

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,45 @@ describe('SubscribeRenderer', () => {
9191
'Could not parse the JSON data while trying to send the request: ',
9292
);
9393
});
94-
});
9594

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-
},
95+
it('should call subscribe and unsubscribe when pressing the send request button', async () => {
96+
jest.spyOn(React, 'useRef').mockReturnValue({
97+
current: {
98+
unsubscribe: mockUnsubscribe,
99+
},
100+
});
101+
render(<SubscribeRenderer name='ticks' auth={1} reqData={request_data} />);
102+
const button = await screen.findByRole('button', { name: /Send Request/i });
103+
expect(button).toBeVisible();
104+
105+
await userEvent.click(button);
106+
expect(mockUnsubscribe).toBeCalledTimes(1);
107+
expect(mockSubscribe).toBeCalledTimes(1);
108+
expect(mockSubscribe).toBeCalledWith({ ticks: 'R_50', subscribe: 1 });
101109
});
102-
render(<SubscribeRenderer name='ticks' auth={1} reqData={request_data} />);
103-
const button = await screen.findByRole('button', { name: /Send Request/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-
});
111110

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();
111+
it('should call unsubscribe when pressing the clear button', async () => {
112+
jest.spyOn(React, 'useRef').mockReturnValue({
113+
current: {
114+
unsubscribe: mockUnsubscribe,
115+
},
116+
});
117+
render(<SubscribeRenderer name='ticks' auth={1} reqData={request_data} />);
118+
const button = await screen.findByRole('button', { name: 'Clear' });
119+
expect(button).toBeVisible();
120+
121+
await userEvent.click(button);
122+
expect(mockUnsubscribe).toBeCalledTimes(1);
123+
});
116124

117-
await userEvent.click(button);
118-
expect(mockUnsubscribe).toBeCalledTimes(1);
125+
it('should call unsubscribe when unmounting the component', async () => {
126+
jest.spyOn(React, 'useRef').mockReturnValue({
127+
current: {
128+
unsubscribe: mockUnsubscribe,
129+
},
130+
});
131+
const { unmount } = render(<SubscribeRenderer name='ticks' auth={1} reqData={request_data} />);
132+
unmount();
133+
expect(mockUnsubscribe).toBeCalledTimes(1);
134+
});
119135
});

0 commit comments

Comments
 (0)