Skip to content

Commit

Permalink
Add toContainElement assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
matycarolina committed Jul 23, 2024
1 parent 7701ff6 commit a5c5cc3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/dom/src/lib/ElementAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,28 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
invertedError,
});
}

/**
* Check if a given container element contains a specified child element.
*
* @returns the assertion instance.
*/
public toContainElement(element: Element): this {
const error = new AssertionError({
actual: this.actual,
message: "Expected the container to contain the element",
});
const invertedError = new AssertionError({
actual: this.actual,
message: "Expected the container to NOT contain the element",
});

return this.execute({
assertWhen: (
this.actual.contains(element)
),
error,
invertedError,
});
}
}

0 comments on commit a5c5cc3

Please sign in to comment.