-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
In order to prevent name clashes with jest-extended, the toBeEmpty will have from now on a more specific name. Co-authored-by: Daniela Valero <[email protected]>
- Loading branch information
1 parent
85cf707
commit 927c5a4
Showing
6 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {render} from './helpers/test-utils' | ||
|
||
test('.toBeEmptyDOMElement', () => { | ||
const {queryByTestId} = render(` | ||
<span data-testid="not-empty"> | ||
<span data-testid="empty"></span> | ||
<svg data-testid="svg-empty"></svg> | ||
</span>`) | ||
|
||
const empty = queryByTestId('empty') | ||
const notEmpty = queryByTestId('not-empty') | ||
const svgEmpty = queryByTestId('svg-empty') | ||
const nonExistantElement = queryByTestId('not-exists') | ||
const fakeElement = {thisIsNot: 'an html element'} | ||
|
||
expect(empty).toBeEmptyDOMElement() | ||
expect(svgEmpty).toBeEmptyDOMElement() | ||
expect(notEmpty).not.toBeEmptyDOMElement() | ||
|
||
// negative test cases wrapped in throwError assertions for coverage. | ||
expect(() => expect(empty).not.toBeEmptyDOMElement()).toThrowError() | ||
|
||
expect(() => expect(svgEmpty).not.toBeEmptyDOMElement()).toThrowError() | ||
|
||
expect(() => expect(notEmpty).toBeEmptyDOMElement()).toThrowError() | ||
|
||
expect(() => expect(fakeElement).toBeEmptyDOMElement()).toThrowError() | ||
|
||
expect(() => { | ||
expect(nonExistantElement).toBeEmptyDOMElement() | ||
}).toThrowError() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {matcherHint, printReceived} from 'jest-matcher-utils' | ||
import {checkHtmlElement} from './utils' | ||
|
||
export function toBeEmptyDOMElement(element) { | ||
checkHtmlElement(element, toBeEmptyDOMElement, this) | ||
|
||
return { | ||
pass: element.innerHTML === '', | ||
message: () => { | ||
return [ | ||
matcherHint( | ||
`${this.isNot ? '.not' : ''}.toBeEmptyDOMElement`, | ||
'element', | ||
'', | ||
), | ||
'', | ||
'Received:', | ||
` ${printReceived(element.innerHTML)}`, | ||
].join('\n') | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters