|
1 | 1 | import {renderIntoDocument} from './helpers/test-utils'
|
2 | 2 | import {screen} from '..'
|
3 | 3 |
|
| 4 | +beforeEach(() => { |
| 5 | + jest.spyOn(console, 'log').mockImplementation(() => {}) |
| 6 | +}) |
| 7 | + |
| 8 | +afterEach(() => { |
| 9 | + console.log.mockRestore() |
| 10 | +}) |
| 11 | + |
4 | 12 | test('exposes queries that are attached to document.body', async () => {
|
5 | 13 | renderIntoDocument(`<div>hello world</div>`)
|
6 | 14 | screen.getByText(/hello world/i)
|
7 | 15 | await screen.findByText(/hello world/i)
|
8 | 16 | expect(screen.queryByText(/hello world/i)).not.toBeNull()
|
9 | 17 | })
|
| 18 | + |
| 19 | +test('exposes debug method', () => { |
| 20 | + renderIntoDocument( |
| 21 | + `<button>test</button><span>multi-test</span><div>multi-test</div>`, |
| 22 | + ) |
| 23 | + // log document |
| 24 | + screen.debug() |
| 25 | + expect(console.log).toHaveBeenCalledTimes(1) |
| 26 | + expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(` |
| 27 | + "<body> |
| 28 | + <button> |
| 29 | + test |
| 30 | + </button> |
| 31 | + <span> |
| 32 | + multi-test |
| 33 | + </span> |
| 34 | + <div> |
| 35 | + multi-test |
| 36 | + </div> |
| 37 | + </body>" |
| 38 | + `) |
| 39 | + console.log.mockClear() |
| 40 | + // log single element |
| 41 | + screen.debug(screen.getByText('test', {selector: 'button'})) |
| 42 | + expect(console.log).toHaveBeenCalledTimes(1) |
| 43 | + expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(` |
| 44 | + "<button> |
| 45 | + test |
| 46 | + </button>" |
| 47 | + `) |
| 48 | + console.log.mockClear() |
| 49 | + // log multiple elements |
| 50 | + screen.debug(screen.getAllByText('multi-test')) |
| 51 | + expect(console.log).toHaveBeenCalledTimes(2) |
| 52 | + expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(` |
| 53 | + "<span> |
| 54 | + multi-test |
| 55 | + </span>" |
| 56 | + `) |
| 57 | + expect(console.log.mock.calls[1][0]).toMatchInlineSnapshot(` |
| 58 | + "<div> |
| 59 | + multi-test |
| 60 | + </div>" |
| 61 | + `) |
| 62 | + console.log.mockClear() |
| 63 | +}) |
| 64 | + |
| 65 | +/* eslint no-console:0 */ |
0 commit comments