Skip to content

Commit 3743d8c

Browse files
committed
test: add mask attr test
1 parent 2fd6bd4 commit 3743d8c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

components/input/__tests__/OTP.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,42 @@ describe('OTP', () => {
113113
wrapper.unmount();
114114
});
115115
});
116+
117+
it('formatter', async () => {
118+
const onChange = jest.fn();
119+
const wrapper = mount(OTP, {
120+
props: { formatter: txt => txt.toUpperCase(), onChange },
121+
sync: false,
122+
});
123+
124+
await asyncExpect(async () => {
125+
const inputAll = wrapper.findAll('input');
126+
const internalValue = 'search'.split('');
127+
for (let i = 0; i < inputAll.length; i++) {
128+
await inputAll[i].setValue(internalValue[i]);
129+
}
130+
131+
expect(onChange).toHaveBeenCalledTimes(1);
132+
expect(onChange).toHaveBeenCalledWith('SEARCH');
133+
134+
wrapper.unmount();
135+
});
136+
});
137+
138+
it('support mask prop', async () => {
139+
const onChange = jest.fn();
140+
const internalValue = 'search'.split('');
141+
const wrapper = mount(OTP, { props: { mask: '🔒', onChange }, sync: false });
142+
143+
await asyncExpect(async () => {
144+
const inputAll = wrapper.findAll('input');
145+
const internalValue = 'search'.split('');
146+
for (let i = 0; i < inputAll.length; i++) {
147+
await inputAll[i].setValue(internalValue[i]);
148+
}
149+
expect(onChange).toHaveBeenCalledTimes(1);
150+
expect(onChange).toHaveBeenCalledWith('search');
151+
expect(getInputAllText(inputAll)).toBe('🔒🔒🔒🔒🔒🔒');
152+
});
153+
});
116154
});

0 commit comments

Comments
 (0)