-
Notifications
You must be signed in to change notification settings - Fork 469
Wait for element to be removed #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f3eca1c
c547962
cc21522
c75e492
a349725
d1d303d
39fea0e
36c4e4c
f5b081d
2dedb1f
54cbc89
999ff5c
e7a018e
0518e78
d6150af
4e2f81c
20ada81
46a952f
618c240
af327d1
505d783
6fcfc83
579c876
2f7452d
20cd110
bc2e3f2
9834de2
17f136f
6664f0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ cache: | |
notifications: | ||
email: false | ||
node_js: | ||
- 'node' | ||
- '10' | ||
- '8' | ||
install: npm install | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,6 @@ | ||
const baseConfig = require('kcd-scripts/jest') | ||
|
||
module.exports = { | ||
collectCoverageFrom: baseConfig.collectCoverageFrom, | ||
coverageThreshold: baseConfig.coverageThreshold, | ||
projects: [ | ||
{ | ||
...baseConfig, | ||
displayName: 'jsdom', | ||
testEnvironment: 'jest-environment-jsdom', | ||
}, | ||
{ | ||
...baseConfig, | ||
displayName: 'node', | ||
testEnvironment: 'jest-environment-node', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, running all the exact same tests in Also, I don't think it's worthwhile to have tests for node. I'm pretty sure there's a very small number of people who benefit from this. |
||
}, | ||
], | ||
// this is for eslint | ||
modulePaths: baseConfig.modulePaths, | ||
...baseConfig, | ||
testEnvironment: 'jest-environment-jsdom', | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'jest-dom/extend-expect' | ||
import {waitForElementToBeRemoved} from '../' | ||
import {render} from './helpers/test-utils' | ||
|
||
jest.useFakeTimers() | ||
|
||
test('requires a function as the first parameter', () => { | ||
return expect( | ||
waitForElementToBeRemoved(), | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"waitForElementToBeRemoved requires a function as the first parameter"`, | ||
) | ||
}) | ||
|
||
test('requires an element to exist first', () => { | ||
return expect( | ||
waitForElementToBeRemoved(() => null), | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"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."`, | ||
) | ||
}) | ||
|
||
test('requires an unempty array of elements to exist first', () => { | ||
return expect( | ||
waitForElementToBeRemoved(() => []), | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"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."`, | ||
) | ||
}) | ||
|
||
test('times out after 4500ms by default', () => { | ||
const {container} = render(`<div></div>`) | ||
const promise = expect( | ||
waitForElementToBeRemoved(() => container), | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"Timed out in waitForElementToBeRemoved."`, | ||
) | ||
jest.advanceTimersByTime(4501) | ||
return promise | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'jest-dom/extend-expect' | ||
import {waitForElementToBeRemoved} from '../' | ||
import {renderIntoDocument} from './helpers/test-utils' | ||
|
||
test('resolves on mutation only when the element is removed', async () => { | ||
const {queryAllByTestId} = renderIntoDocument(` | ||
<div data-testid="div"></div> | ||
<div data-testid="div"></div> | ||
`) | ||
const divs = queryAllByTestId('div') | ||
// first mutation | ||
setTimeout(() => { | ||
divs.forEach(d => d.setAttribute('id', 'mutated')) | ||
}) | ||
// removal | ||
setTimeout(() => { | ||
divs.forEach(div => div.parentElement.removeChild(div)) | ||
}, 100) | ||
// the timeout is here for two reasons: | ||
// 1. It helps test the timeout config | ||
// 2. The element should be removed immediately | ||
// so if it doesn't in the first 100ms then we know something's wrong | ||
// so we'll fail early and not wait the full timeout | ||
await waitForElementToBeRemoved(() => queryAllByTestId('div'), {timeout: 200}) | ||
}) | ||
|
||
test('resolves on mutation if callback throws an error', async () => { | ||
const {getByTestId} = renderIntoDocument(` | ||
<div data-testid="div"></div> | ||
`) | ||
const div = getByTestId('div') | ||
setTimeout(() => { | ||
div.parentElement.removeChild(div) | ||
}) | ||
await waitForElementToBeRemoved(() => getByTestId('div'), {timeout: 100}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this opens us up to stuff like this: https://stackoverflow.com/questions/55059748/travis-jest-typeerror-cannot-assign-to-read-only-property-symbolsymbol-tostr
I think the benefit of testing an unstable version of node isn't worth stuff like this.