Skip to content
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

Wait for element to be removed #218

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f3eca1c
Add tests and snapshots
Tolsee Feb 22, 2019
c547962
Implement waitForElementToBeRemoved method
Tolsee Feb 22, 2019
cc21522
Export waitForElementToBeRemoved
Tolsee Feb 22, 2019
c75e492
Add as contributor
Tolsee Feb 22, 2019
a349725
Update README.md after rebase
Tolsee Feb 22, 2019
d1d303d
Throw error is the element is not present in the first place
Tolsee Feb 23, 2019
39fea0e
Add test for full coverage
Tolsee Feb 23, 2019
36c4e4c
User jest time faker
Tolsee Feb 24, 2019
f5b081d
Add typings
Tolsee Feb 24, 2019
2dedb1f
Cleanup
Tolsee Feb 24, 2019
54cbc89
Update snapshot
Tolsee Feb 24, 2019
999ff5c
Get rid of iife
Tolsee Feb 25, 2019
e7a018e
Cleanup from review
Tolsee Feb 26, 2019
0518e78
Check for empty array as well
Tolsee Feb 26, 2019
d6150af
Check for error, falsy and empty to check whether the element is removed
Tolsee Feb 26, 2019
4e2f81c
error not defined error fix
Tolsee Feb 27, 2019
20ada81
Change snapshot to inline snapshot
Tolsee Feb 27, 2019
46a952f
Update snapshot
Tolsee Feb 27, 2019
618c240
Merge branch 'ts-wait-for-element-to-be-removed' of https://github.co…
Tolsee Feb 27, 2019
af327d1
Merge branch 'master' into ts-wait-for-element-to-be-removed
Tolsee Feb 27, 2019
505d783
Only observe mutations if synchronous test passes
Tolsee Feb 27, 2019
6fcfc83
only observer if synchronous test passes fix
Tolsee Feb 27, 2019
579c876
Await for the respective promise to resolve in test
Tolsee Feb 27, 2019
2f7452d
Snapshot test to normal toHaveBeenCalledWith assertions
Tolsee Feb 28, 2019
20cd110
Update comment
Tolsee Feb 28, 2019
bc2e3f2
Remove comment
Tolsee Feb 28, 2019
9834de2
test: improve tests for wait-for-element-to-be-removed
Mar 9, 2019
17f136f
test: fix everything
Mar 9, 2019
6664f0a
test: do not test unstable node versions
Mar 9, 2019
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
Prev Previous commit
Next Next commit
Add test for full coverage
  • Loading branch information
Tolsee committed Feb 23, 2019
commit 39fea0eee314795564f9d3dc878713bcf26988b0
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Array [
]
`;

exports[`it returns error immediately if there callback returns falsy value or error before any mutations 2`] = `
Array [
[ReferenceError: timer is not defined],
Tolsee marked this conversation as resolved.
Show resolved Hide resolved
]
`;

exports[`it throws if timeout is exceeded 1`] = `
Array [
[Error: Timed out in waitForElementToBeRemoved.],
Expand Down
21 changes: 15 additions & 6 deletions src/__tests__/wait-for-element-to-be-removed.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,36 +185,45 @@ test('it throws if timeout is exceeded', async () => {
test('it returns error immediately if there callback returns falsy value or error before any mutations', async () => {
const {container, getByTestId} = render(``)

const callback = jest
const callbackForError = jest
.fn(() => getByTestId('initial-element'))
.mockName('callback')
const callbackForFalsy = jest.fn(() => false).mockName('callback')
const successHandler = jest.fn().mockName('successHandler')
const errorHandler = jest.fn().mockName('errorHandler')

waitForElementToBeRemoved(callback, {
waitForElementToBeRemoved(callbackForError, {
container,
timeout: 70,
mutationObserverOptions: {attributes: true},
}).then(successHandler, errorHandler)
waitForElementToBeRemoved(callbackForFalsy, {
container,
timeout: 70,
mutationObserverOptions: {attributes: true},
}).then(successHandler, errorHandler)

// One synchronous `callback` call is expected.
expect(callback).toHaveBeenCalledTimes(1)
expect(callbackForError).toHaveBeenCalledTimes(1)
expect(callbackForFalsy).toHaveBeenCalledTimes(1)

// The promise callbacks are expected to be called asyncronously.
expect(successHandler).toHaveBeenCalledTimes(0)
expect(errorHandler).toHaveBeenCalledTimes(0)
await wait()
expect(successHandler).toHaveBeenCalledTimes(0)
expect(errorHandler).toHaveBeenCalledTimes(1)
expect(errorHandler).toHaveBeenCalledTimes(2)

container.setAttribute('data-test-attribute', 'something changed once')
await skipSomeTimeForMutationObserver(50)

// No more calls are expected.
expect(callback).toHaveBeenCalledTimes(1)
expect(callbackForError).toHaveBeenCalledTimes(1)
expect(callbackForFalsy).toHaveBeenCalledTimes(1)
expect(successHandler).toHaveBeenCalledTimes(0)
expect(errorHandler).toHaveBeenCalledTimes(1)
expect(errorHandler).toHaveBeenCalledTimes(2)
expect(errorHandler.mock.calls[0]).toMatchSnapshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm fine with this being a snapshot, but please make it inline.

expect(errorHandler.mock.calls[1]).toMatchSnapshot()
})

test('works if a container is not defined', async () => {
Expand Down