Skip to content

Commit c816955

Browse files
authored
doc: Better documentation for toContaintHTML (#363)
* doc: Better documentation for toContaintHTML
1 parent 637529e commit c816955

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ toContainHTML(htmlText: string)
491491
```
492492

493493
Assert whether a string representing a HTML element is contained in another
494-
element:
494+
element. The string should contain valid html, and not any incomplete html.
495495

496496
#### Examples
497497

@@ -500,7 +500,15 @@ element:
500500
```
501501

502502
```javascript
503+
// These are valid uses
503504
expect(getByTestId('parent')).toContainHTML('<span data-testid="child"></span>')
505+
expect(getByTestId('parent')).toContainHTML('<span data-testid="child" />')
506+
expect(getByTestId('parent')).not.toContainHTML('<br />')
507+
508+
// These won't work
509+
expect(getByTestId('parent')).toContainHTML('data-testid="child"')
510+
expect(getByTestId('parent')).toContainHTML('data-testid')
511+
expect(getByTestId('parent')).toContainHTML('</span>')
504512
```
505513

506514
> Chances are you probably do not need to use this matcher. We encourage testing

0 commit comments

Comments
 (0)