Skip to content

Commit

Permalink
test: ensure initial validation with constraints and value (#4410)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Aug 29, 2022
1 parent f4b11b8 commit d5cf964
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions packages/text-area/test/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,43 @@ describe('validation', () => {
textArea.remove();
});

it('should not validate by default', async () => {
it('should not validate without value', async () => {
document.body.appendChild(textArea);
await nextRender();
expect(validateSpy.called).to.be.false;
});

it('should not validate when the field has an initial value', async () => {
textArea.value = 'Initial Value';
document.body.appendChild(textArea);
await nextRender();
expect(validateSpy.called).to.be.false;
});

it('should not validate when the field has an initial value and invalid', async () => {
textArea.value = 'Initial Value';
textArea.invalid = true;
document.body.appendChild(textArea);
await nextRender();
expect(validateSpy.called).to.be.false;
describe('with value', () => {
beforeEach(() => {
textArea.value = 'Value';
});

it('should not validate by default', async () => {
document.body.appendChild(textArea);
await nextRender();
expect(validateSpy.called).to.be.false;
});

it('should not validate when the field has invalid', async () => {
textArea.invalid = true;
document.body.appendChild(textArea);
await nextRender();
expect(validateSpy.called).to.be.false;
});

it('should validate when the field has minlength', async () => {
textArea.minlength = 2;
document.body.appendChild(textArea);
await nextRender();
expect(validateSpy.calledOnce).to.be.true;
});

it('should validate when the field has maxlength', async () => {
textArea.maxlength = 2;
document.body.appendChild(textArea);
await nextRender();
expect(validateSpy.calledOnce).to.be.true;
});
});
});

Expand Down

0 comments on commit d5cf964

Please sign in to comment.