/
to-be-empty.js
35 lines (27 loc) · 1.12 KB
/
to-be-empty.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {render} from './helpers/test-utils'
test('.toBeEmpty', () => {
// @deprecated intentionally hiding warnings for test clarity
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
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).toBeEmpty()
expect(svgEmpty).toBeEmpty()
expect(notEmpty).not.toBeEmpty()
// negative test cases wrapped in throwError assertions for coverage.
expect(() => expect(empty).not.toBeEmpty()).toThrowError()
expect(() => expect(svgEmpty).not.toBeEmpty()).toThrowError()
expect(() => expect(notEmpty).toBeEmpty()).toThrowError()
expect(() => expect(fakeElement).toBeEmpty()).toThrowError()
expect(() => {
expect(nonExistantElement).toBeEmpty()
}).toThrowError()
spy.mockRestore()
})