-
Notifications
You must be signed in to change notification settings - Fork 60
/
useShowPopup.test.ts
33 lines (29 loc) · 909 Bytes
/
useShowPopup.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { renderHook } from '@testing-library/react';
import useShowPopup from '../src/useShowPopup';
import { useWebApp } from '../src/core';
import { WebApp } from '../src/core/twa-types';
describe('useShowPopup', () => {
it('checks correct call WebApp.showPopup api', async () => {
const { result } = renderHook(useShowPopup);
const showPopup = result.current;
const spyShowPopup = jest
.spyOn(useWebApp() as WebApp, 'showPopup')
.mockImplementation((_, callback) => {
callback!('buttonId');
});
const params = {
title: 'title',
message: 'message',
buttons: [
{
id: 'buttonId',
type: 'cancel',
text: 'textButton',
},
],
};
const button = await showPopup(params);
expect(spyShowPopup).toBeCalledWith(params, expect.any(Function));
expect(button).toBe('buttonId');
});
});