Skip to content

Commit

Permalink
fix: improve error messages for .toBeInTheDocument (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
kandros authored and gnapse committed Nov 1, 2019
1 parent 281e167 commit c12a476
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/to-be-in-the-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export function toBeInTheDocument(element) {
const pass =
element === null ? false : element.ownerDocument.contains(element)

const errorFound = () => {
return `expected document not to contain element, found ${stringify(
element.cloneNode(true),
)} instead`
}
const errorNotFound = () => {
return `element could not be found in the document`
}

return {
pass,
message: () => {
Expand All @@ -23,10 +32,7 @@ export function toBeInTheDocument(element) {
'',
),
'',
receivedColor(`${stringify(element.ownerDocument.cloneNode(false))} ${
this.isNot ? 'contains:' : 'does not contain:'
} ${stringify(element.cloneNode(false))}
`),
receivedColor(this.isNot ? errorFound() : errorNotFound()),
].join('\n')
},
}
Expand Down

0 comments on commit c12a476

Please sign in to comment.