|
| 1 | +import {render} from './helpers/test-utils' |
| 2 | + |
| 3 | +describe('.toAppearBefore', () => { |
| 4 | + const {queryByTestId} = render(` |
| 5 | + <div> |
| 6 | + <div data-testid='div-a'> |
| 7 | + <span data-testid='text-a'>Text A</span> |
| 8 | + <span data-testid='text-b'>Text B</span> |
| 9 | + </div> |
| 10 | + </div> |
| 11 | + `) |
| 12 | + |
| 13 | + const textA = queryByTestId('text-a') |
| 14 | + const textB = queryByTestId('text-b') |
| 15 | + const divA = queryByTestId('div-a') |
| 16 | + |
| 17 | + it('returns correct result when first element is before second element', () => { |
| 18 | + expect(textA).toAppearBefore(textB) |
| 19 | + }) |
| 20 | + |
| 21 | + it('returns correct for .not() invocation', () => { |
| 22 | + expect(textB).not.toAppearBefore(textA) |
| 23 | + }) |
| 24 | + |
| 25 | + it('errors out when first element is not before second element', () => { |
| 26 | + expect(() => expect(textB).toAppearBefore(textA)).toThrowError( |
| 27 | + /Received: Node.DOCUMENT_POSITION_PRECEDING \(2\)/i, |
| 28 | + ) |
| 29 | + }) |
| 30 | + |
| 31 | + it('errors out when first element is parent of second element', () => { |
| 32 | + expect(() => expect(divA).toAppearBefore(textA)).toThrowError( |
| 33 | + /Received: Unknown document position \(20\)/i, |
| 34 | + ) |
| 35 | + }) |
| 36 | + |
| 37 | + it('errors out when first element is child of second element', () => { |
| 38 | + expect(() => expect(textA).toAppearBefore(divA)).toThrowError( |
| 39 | + /Received: Unknown document position \(10\)/i, |
| 40 | + ) |
| 41 | + }) |
| 42 | + |
| 43 | + it('errors out when either first or second element is not HTMLElement', () => { |
| 44 | + expect(() => expect(1).toAppearBefore(textB)).toThrowError() |
| 45 | + expect(() => expect(textA).toAppearBefore(1)).toThrowError() |
| 46 | + }) |
| 47 | +}) |
| 48 | + |
| 49 | +describe('.toAppearAfter', () => { |
| 50 | + const {queryByTestId} = render(` |
| 51 | + <div> |
| 52 | + <div data-testid='div-a'> |
| 53 | + <span data-testid='text-a'>Text A</span> |
| 54 | + <span data-testid='text-b'>Text B</span> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + `) |
| 58 | + |
| 59 | + const textA = queryByTestId('text-a') |
| 60 | + const textB = queryByTestId('text-b') |
| 61 | + const divA = queryByTestId('div-a') |
| 62 | + |
| 63 | + it('returns correct result when first element is after second element', () => { |
| 64 | + expect(textB).toAppearAfter(textA) |
| 65 | + }) |
| 66 | + |
| 67 | + it('returns correct for .not() invocation', () => { |
| 68 | + expect(textA).not.toAppearAfter(textB) |
| 69 | + }) |
| 70 | + |
| 71 | + it('errors out when first element is not after second element', () => { |
| 72 | + expect(() => expect(textA).toAppearAfter(textB)).toThrowError( |
| 73 | + /Received: Node.DOCUMENT_POSITION_FOLLOWING \(4\)/i, |
| 74 | + ) |
| 75 | + }) |
| 76 | + |
| 77 | + it('errors out when first element is parent of second element', () => { |
| 78 | + expect(() => expect(divA).toAppearAfter(textA)).toThrowError( |
| 79 | + /Received: Unknown document position \(20\)/i, |
| 80 | + ) |
| 81 | + }) |
| 82 | + |
| 83 | + it('errors out when first element is child of second element', () => { |
| 84 | + expect(() => expect(textA).toAppearAfter(divA)).toThrowError( |
| 85 | + /Received: Unknown document position \(10\)/i, |
| 86 | + ) |
| 87 | + }) |
| 88 | + |
| 89 | + it('errors out when either first or second element is not HTMLElement', () => { |
| 90 | + expect(() => expect(1).toAppearAfter(textB)).toThrowError() |
| 91 | + expect(() => expect(textA).toAppearAfter(1)).toThrowError() |
| 92 | + }) |
| 93 | +}) |
0 commit comments