-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a8072d
commit 4c63680
Showing
4 changed files
with
62 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { render, screen } from '../..'; | ||
import '../extend-expect'; | ||
|
||
test('.toBeEmptyElement', () => { | ||
render( | ||
<View testID="not-empty"> | ||
<View testID="empty" /> | ||
</View> | ||
); | ||
|
||
const empty = screen.getByTestId('empty'); | ||
const notEmpty = screen.queryByTestId('not-empty'); | ||
const nonExistentElement = screen.queryByTestId('not-exists'); | ||
const fakeElement = { thisIsNot: 'an html element' }; | ||
|
||
expect(empty).toBeEmptyElement(); | ||
expect(notEmpty).not.toBeEmptyElement(); | ||
|
||
expect(() => expect(empty).not.toBeEmptyElement()).toThrow(); | ||
|
||
expect(() => expect(notEmpty).toBeEmptyElement()).toThrow(); | ||
|
||
expect(() => expect(fakeElement).toBeEmptyElement()).toThrow(); | ||
|
||
expect(() => { | ||
expect(nonExistentElement).toBeEmptyElement(); | ||
}).toThrow(); | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
/// <reference path="./extend-expect.d.ts" /> | ||
|
||
import { toBeOnTheScreen } from './to-be-on-the-screen'; | ||
import { toBeEmptyElement } from './to-be-empty-element'; | ||
|
||
expect.extend({ | ||
toBeOnTheScreen, | ||
toBeEmptyElement, | ||
}); |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { toBeOnTheScreen } from './to-be-on-the-screen'; | ||
export { toBeEmptyElement } from './to-be-empty-element'; |
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,29 @@ | ||
import { ReactTestInstance } from 'react-test-renderer'; | ||
import { matcherHint, printReceived } from 'jest-matcher-utils'; | ||
import { getHostChildren } from '../helpers/component-tree'; | ||
import { checkHostElement } from './utils'; | ||
|
||
export function toBeEmptyElement( | ||
this: jest.MatcherContext, | ||
element: ReactTestInstance | ||
) { | ||
checkHostElement(element, toBeEmptyElement, this); | ||
|
||
const pass = getHostChildren(element).length === 0; | ||
|
||
return { | ||
pass, | ||
message: () => { | ||
return [ | ||
matcherHint( | ||
`${this.isNot ? '.not' : ''}.toBeEmptyElement`, | ||
'element', | ||
'' | ||
), | ||
'', | ||
'Received:', | ||
` ${printReceived(element.children)}`, | ||
].join('\n'); | ||
}, | ||
}; | ||
} |