|
1 | 1 | import {render} from './helpers/test-utils'
|
2 | 2 |
|
3 |
| -test('.toHaveTextContent', () => { |
4 |
| - const {queryByTestId} = render(`<span data-testid="count-value">2</span>`) |
5 |
| - |
6 |
| - expect(queryByTestId('count-value')).toHaveTextContent('2') |
7 |
| - expect(queryByTestId('count-value')).toHaveTextContent(2) |
8 |
| - expect(queryByTestId('count-value')).toHaveTextContent(/2/) |
9 |
| - expect(queryByTestId('count-value')).not.toHaveTextContent('21') |
10 |
| - expect(() => |
11 |
| - expect(queryByTestId('count-value2')).toHaveTextContent('2'), |
12 |
| - ).toThrowError() |
13 |
| - |
14 |
| - expect(() => |
15 |
| - expect(queryByTestId('count-value')).toHaveTextContent('3'), |
16 |
| - ).toThrowError() |
17 |
| - expect(() => |
18 |
| - expect(queryByTestId('count-value')).not.toHaveTextContent('2'), |
19 |
| - ).toThrowError() |
| 3 | +describe('.toHaveTextContent', () => { |
| 4 | + test('handles positive test cases', () => { |
| 5 | + const {queryByTestId} = render(`<span data-testid="count-value">2</span>`) |
| 6 | + |
| 7 | + expect(queryByTestId('count-value')).toHaveTextContent('2') |
| 8 | + expect(queryByTestId('count-value')).toHaveTextContent(2) |
| 9 | + expect(queryByTestId('count-value')).toHaveTextContent(/2/) |
| 10 | + expect(queryByTestId('count-value')).not.toHaveTextContent('21') |
| 11 | + }) |
| 12 | + |
| 13 | + test('handles negative test cases', () => { |
| 14 | + const {queryByTestId} = render(`<span data-testid="count-value">2</span>`) |
| 15 | + |
| 16 | + expect(() => |
| 17 | + expect(queryByTestId('count-value2')).toHaveTextContent('2'), |
| 18 | + ).toThrowError() |
| 19 | + |
| 20 | + expect(() => |
| 21 | + expect(queryByTestId('count-value')).toHaveTextContent('3'), |
| 22 | + ).toThrowError() |
| 23 | + expect(() => |
| 24 | + expect(queryByTestId('count-value')).not.toHaveTextContent('2'), |
| 25 | + ).toThrowError() |
| 26 | + }) |
| 27 | + |
| 28 | + test('normalizes whitespace by default', () => { |
| 29 | + const {container} = render(` |
| 30 | + <span> |
| 31 | + Step |
| 32 | + 1 |
| 33 | + of |
| 34 | + 4 |
| 35 | + </span> |
| 36 | + `) |
| 37 | + |
| 38 | + expect(container.querySelector('span')).toHaveTextContent('Step 1 of 4') |
| 39 | + }) |
| 40 | + |
| 41 | + test('allows whitespace normalization to be turned off', () => { |
| 42 | + const {container} = render(`<span> Step 1 of 4</span>`) |
| 43 | + |
| 44 | + expect(container.querySelector('span')).toHaveTextContent(' Step 1 of 4', { |
| 45 | + normalizeWhitespace: false, |
| 46 | + }) |
| 47 | + }) |
20 | 48 | })
|
0 commit comments