-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathindex.test.ts
112 lines (107 loc) · 2.64 KB
/
index.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { getInstance } from 'tests/utils';
import { describe, it, expect, vi } from 'vitest';
describe('init', () => {
it('测试默认值', () => {
const instance = getInstance('Modal', {});
const {
bodyClassName,
bodyStyle,
maskClassName,
maskStyle,
maskClosable,
type,
closable,
duration,
animation,
zIndex,
title,
content,
visible,
destroyOnClose,
primaryButtonText,
secondaryButtonText,
cancelButtonText,
primaryButtonStyle,
secondaryButtonStyle,
cancelButtonStyle,
} = instance.getConfig().props;
expect({
bodyClassName,
bodyStyle,
maskClassName,
maskStyle,
maskClosable,
type,
closable,
duration,
animation,
zIndex,
title,
content,
visible,
destroyOnClose,
primaryButtonText,
secondaryButtonText,
cancelButtonText,
primaryButtonStyle,
secondaryButtonStyle,
cancelButtonStyle,
}).toMatchFileSnapshot('snapshot/alipay_config_props.txt');
});
});
describe('modal onClose', () => {
it('modal onClose', () => {
const onClose = vi.fn();
const instance = getInstance('Modal', {
onClose,
});
instance.callMethod('onClose');
expect(onClose).toBeCalled();
});
});
describe('modal onMaskClose', () => {
it('modal onMaskClose', () => {
const onClose = vi.fn();
const instance = getInstance('Modal', {
onClose,
maskClosable: true,
});
instance.callMethod('onMaskClose');
expect(onClose).toBeCalled();
});
it('maskClosable false', () => {
const onClose = vi.fn();
const instance = getInstance('Modal', {
onClose,
maskClosable: false,
});
instance.callMethod('onMaskClose');
expect(onClose).not.toBeCalled();
});
});
describe('modal button function', () => {
it('modal onPrimaryButtonTap', () => {
const onPrimaryButtonTap = vi.fn();
const instance = getInstance('Modal', {
onPrimaryButtonTap,
});
instance.callMethod('onPrimaryButtonTap');
expect(onPrimaryButtonTap).toBeCalled();
});
it('modal onSecondaryButtonTap', () => {
const onSecondaryButtonTap = vi.fn();
const instance = getInstance('Modal', {
onSecondaryButtonTap,
});
instance.callMethod('onSecondaryButtonTap');
expect(onSecondaryButtonTap).toBeCalled();
});
it('modal onCancelButtonTap', () => {
const onCancelButtonTap = vi.fn();
const instance = getInstance('Modal', {
onCancelButtonTap,
});
instance.callMethod('onCancelButtonTap');
expect(onCancelButtonTap).toBeCalled();
});
});