|
| 1 | +import 'jest-dom/extend-expect' |
| 2 | +import {waitForElementToBeRemoved} from '../' |
| 3 | +import {render} from './helpers/test-utils' |
| 4 | + |
| 5 | +jest.useFakeTimers() |
| 6 | + |
| 7 | +// const skipSomeTimeForMutationObserver = (delayMs = 50) => { |
| 8 | +// jest.advanceTimersByTime(delayMs) |
| 9 | +// jest.runAllImmediates() |
| 10 | +// } |
| 11 | + |
| 12 | +test('requires a function as the first parameter', () => { |
| 13 | + return expect( |
| 14 | + waitForElementToBeRemoved(), |
| 15 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 16 | + `"waitForElementToBeRemoved requires a function as the first parameter"`, |
| 17 | + ) |
| 18 | +}) |
| 19 | + |
| 20 | +test('requires an element to exist first', () => { |
| 21 | + return expect( |
| 22 | + waitForElementToBeRemoved(() => null), |
| 23 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 24 | + `"The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal."`, |
| 25 | + ) |
| 26 | +}) |
| 27 | + |
| 28 | +test('requires an unempty array of elements to exist first', () => { |
| 29 | + return expect( |
| 30 | + waitForElementToBeRemoved(() => []), |
| 31 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 32 | + `"The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal."`, |
| 33 | + ) |
| 34 | +}) |
| 35 | + |
| 36 | +test('times out after 4500ms by default', () => { |
| 37 | + const {container} = render(`<div></div>`) |
| 38 | + const promise = expect( |
| 39 | + waitForElementToBeRemoved(() => container), |
| 40 | + ).rejects.toThrowErrorMatchingInlineSnapshot( |
| 41 | + `"Timed out in waitForElementToBeRemoved."`, |
| 42 | + ) |
| 43 | + jest.advanceTimersByTime(4501) |
| 44 | + return promise |
| 45 | +}) |
0 commit comments