Skip to content

Commit

Permalink
test(chips): harness will use trailing action if there isn't a primary
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 542661036
  • Loading branch information
asyncLiz authored and copybara-github committed Jun 22, 2023
1 parent 224a73b commit 4ec6d4e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions chips/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ export class ChipHarness extends Harness<Chip> {

protected override async getInteractiveElement() {
await this.element.updateComplete;
if (this.action === 'trailing') {
// Retrieve MultiActionChip's trailingAction
const {trailingAction} =
this.element as {trailingAction?: HTMLElement | null};
const {primaryId} = this.element as unknown as {primaryId: string};
const primaryAction = primaryId &&
this.element.renderRoot.querySelector<HTMLElement>(`#${primaryId}`);
// Retrieve MultiActionChip's trailingAction
const {trailingAction} =
this.element as {trailingAction?: HTMLElement | null};

// Default to trailing action if there isn't a primary action and the user
// didn't explicitly set `harness.action = 'trailing'` (remove-only input
// chips).
if (this.action === 'trailing' || !primaryAction) {
if (!trailingAction) {
throw new Error(
'`ChipHarness.action` is "trailing", but the chip does not have a trailing action.');
Expand All @@ -28,9 +35,6 @@ export class ChipHarness extends Harness<Chip> {
return trailingAction;
}

const {primaryId} = this.element as unknown as {primaryId: string};
const primaryAction = primaryId &&
this.element.renderRoot.querySelector<HTMLElement>(`#${primaryId}`);
if (!primaryAction) {
throw new Error(
'`ChipHarness.action` is "primary", but the chip does not have a primary action.');
Expand Down

0 comments on commit 4ec6d4e

Please sign in to comment.