Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/__tests__/wait-for-element-to-be-removed.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ test('requires an unempty array of elements to exist first (function form)', ()
)
})

test('after successful removal, fullfills promise with empty value (undefined)', () => {
const {getByTestId} = renderIntoDocument(`
<div data-testid="div"></div>
`)
const div = getByTestId('div')
const waitResult = waitForElementToBeRemoved(() => getByTestId('div'), {
timeout: 100,
})
div.parentElement.removeChild(div)
return expect(waitResult).resolves.toBeUndefined()
})

describe('timers', () => {
const expectElementToBeRemoved = async () => {
const importedWaitForElementToBeRemoved = importModule()
Expand Down
4 changes: 2 additions & 2 deletions src/wait-for-element-to-be-removed.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ async function waitForElementToBeRemoved(callback, options) {
result = callback()
} catch (error) {
if (error.name === 'TestingLibraryElementError') {
return true
return undefined
}
throw error
}
if (!isRemoved(result)) {
throw timeoutError
}
return true
return undefined
}, options)
}

Expand Down
2 changes: 1 addition & 1 deletion types/wait-for-element-to-be-removed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { waitForOptions } from "./wait-for";
export function waitForElementToBeRemoved<T>(
callback: (() => T) | T,
options?: waitForOptions,
): Promise<T>;
): Promise<void>;