Skip to content

Commit 920d216

Browse files
committed
Add uui-input tests for setCustomValidity
1 parent 3a825db commit 920d216

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/uui-input/lib/uui-input.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe('UuiInput in Form', () => {
186186
});
187187
});
188188

189-
describe('custom error', () => {
189+
describe('custom error though attributes', () => {
190190
beforeEach(async () => {
191191
element.setAttribute('error', 'true');
192192
await elementUpdated(element);
@@ -212,6 +212,32 @@ describe('UuiInput in Form', () => {
212212
expect(formElement.checkValidity()).to.be.true;
213213
});
214214
});
215+
216+
describe('custom error through setCustomValidity', () => {
217+
it('sets element to invalid when it sets custom validity', async () => {
218+
const validationMessage = 'custom error';
219+
element.setCustomValidity(validationMessage);
220+
expect(element.checkValidity()).to.be.false;
221+
expect(element.validationMessage).to.equal(validationMessage);
222+
});
223+
224+
it('sets the form to invalid when value is empty', async () => {
225+
element.setCustomValidity('custom error');
226+
expect(formElement.checkValidity()).to.be.false;
227+
});
228+
229+
it('sets element to valid when it sets custom validity to an empty string', async () => {
230+
const validationMessage = '';
231+
element.setCustomValidity(validationMessage);
232+
expect(element.checkValidity()).to.be.true;
233+
expect(element.validationMessage).to.equal(validationMessage);
234+
});
235+
236+
it('sets the form to valid when it doesnt have custom validity', async () => {
237+
element.setCustomValidity('');
238+
expect(formElement.checkValidity()).to.be.true;
239+
});
240+
});
215241
});
216242

217243
describe('native validation', () => {

0 commit comments

Comments
 (0)