Skip to content

Commit

Permalink
fix(components/forms): update checkbox and checkbox group harness to …
Browse files Browse the repository at this point in the history
…return false instead of throw when no form errors are present (#2640)
  • Loading branch information
Blackbaud-CoreyArcher authored Aug 27, 2024
1 parent adc71fc commit 28c1fdd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ describe('Checkbox group harness', () => {

await checkboxHarness.check();

await expectAsync(
checkboxGroupHarness.hasError('test'),
).toBeRejectedWithError('No form errors found.');
await expectAsync(checkboxGroupHarness.hasError('test')).toBeResolvedTo(
false,
);
});

it('should throw an error if no help inline is found', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,11 @@ export class SkyCheckboxGroupHarness extends SkyComponentHarness {
}

async #getFormErrors(): Promise<SkyFormErrorsHarness> {
const errorsHarness = await this.locatorFor(
return await this.locatorFor(
SkyFormErrorsHarness.with({
dataSkyId: 'checkbox-group-form-errors',
}),
)();

const errors = await errorsHarness.getFormErrors();

if (errors.length) {
return errorsHarness;
}

throw Error('No form errors found.');
}

async #getHelpInline(): Promise<SkyHelpInlineHarness> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SkyHelpService } from '@skyux/core';
import { SkyHelpTestingModule } from '@skyux/core/testing';

Expand All @@ -9,7 +10,11 @@ import { CheckboxHarnessTestModule } from './fixtures/checkbox-harness-test.modu

async function setupTest(
options: { dataSkyId?: string; hideEmailLabel?: boolean } = {},
) {
): Promise<{
checkboxHarness: SkyCheckboxHarness;
fixture: ComponentFixture<CheckboxHarnessTestComponent>;
loader: HarnessLoader;
}> {
await TestBed.configureTestingModule({
imports: [CheckboxHarnessTestModule, SkyHelpTestingModule],
}).compileComponents();
Expand Down Expand Up @@ -227,9 +232,7 @@ describe('Checkbox harness', () => {
dataSkyId: 'my-email-checkbox',
});

await expectAsync(checkboxHarness.hasRequiredError()).toBeRejectedWithError(
'No form errors found.',
);
await expectAsync(checkboxHarness.hasRequiredError()).toBeResolvedTo(false);
});

it('should throw an error if no help inline is found', async () => {
Expand Down
10 changes: 1 addition & 9 deletions libs/components/forms/testing/src/checkbox/checkbox-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,7 @@ export class SkyCheckboxHarness extends SkyComponentHarness {
}

async #getFormErrors(): Promise<SkyFormErrorsHarness> {
const errorsHarness = await this.locatorFor(SkyFormErrorsHarness)();

const errors = await errorsHarness.getFormErrors();

if (errors.length) {
return errorsHarness;
}

throw Error('No form errors found.');
return await this.locatorFor(SkyFormErrorsHarness)();
}

async #getHelpInline(): Promise<SkyHelpInlineHarness> {
Expand Down

0 comments on commit 28c1fdd

Please sign in to comment.