Skip to content

Commit c12a476

Browse files
kandrosgnapse
authored andcommitted
fix: improve error messages for .toBeInTheDocument (#137)
1 parent 281e167 commit c12a476

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/to-be-in-the-document.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export function toBeInTheDocument(element) {
1313
const pass =
1414
element === null ? false : element.ownerDocument.contains(element)
1515

16+
const errorFound = () => {
17+
return `expected document not to contain element, found ${stringify(
18+
element.cloneNode(true),
19+
)} instead`
20+
}
21+
const errorNotFound = () => {
22+
return `element could not be found in the document`
23+
}
24+
1625
return {
1726
pass,
1827
message: () => {
@@ -23,10 +32,7 @@ export function toBeInTheDocument(element) {
2332
'',
2433
),
2534
'',
26-
receivedColor(`${stringify(element.ownerDocument.cloneNode(false))} ${
27-
this.isNot ? 'contains:' : 'does not contain:'
28-
} ${stringify(element.cloneNode(false))}
29-
`),
35+
receivedColor(this.isNot ? errorFound() : errorNotFound()),
3036
].join('\n')
3137
},
3238
}

0 commit comments

Comments
 (0)