Skip to content

Commit

Permalink
feat: implement id filter for div harness (onecx#643)
Browse files Browse the repository at this point in the history
Co-authored-by: Bastian Jakobi <[email protected]>
  • Loading branch information
2 people authored and markuczy committed Jan 17, 2025
1 parent 85fd00c commit 4fb2166
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libs/angular-testing/src/lib/harnesses/div.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular

export interface DivHarnessFilters extends BaseHarnessFilters {
class?: string
id?: string
}

export class DivHarness extends ComponentHarness {
static hostSelector = 'div'

static with(options: DivHarnessFilters): HarnessPredicate<DivHarness> {
return new HarnessPredicate(DivHarness, options).addOption('class', options.class, (harness, c) =>
HarnessPredicate.stringMatches(harness.getByClass(c), c)
return new HarnessPredicate(DivHarness, options)
.addOption('id', options.id, (harness, id) => HarnessPredicate.stringMatches(harness.getId(), id))
.addOption('class', options.class, (harness, c) => HarnessPredicate.stringMatches(harness.getByClass(c), c)
)
}

async getByClass(c: string): Promise<string> {
return (await (await this.host()).hasClass(c)) ? c : ''
}

async getId(): Promise<string | null> {
return await (await this.host()).getAttribute('id')
}

async checkHasClass(value: string) {
return await (await this.host()).hasClass(value)
}
Expand Down

0 comments on commit 4fb2166

Please sign in to comment.