Skip to content

Commit

Permalink
fix: add check prev element (#8289)
Browse files Browse the repository at this point in the history
<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->

## Purpose
_Describe the problem you want to address or the feature you want to
implement._

## Approach
_Describe how your changes address the issue or implement the desired
functionality in as much detail as possible._

## References
close #8264 

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail
  • Loading branch information
PavelMor25 authored Sep 30, 2024
1 parent a99f1cc commit 9e0e580
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/client/automation/playback/move/event-sequence/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export default class MoveEventSequenceBase {
}

run (currentElement, prevElement, options, dragElement, dragDataStore) {

const prevElementInDocument = prevElement && domUtils.isElementInDocument(prevElement);

const prevElementInRemovedIframe = prevElement && domUtils.isElementInIframe(prevElement) &&
!domUtils.getIframeByElement(prevElement);

if (!prevElementInDocument || prevElementInRemovedIframe)
prevElement = null;

const elementChanged = currentElement !== prevElement;
const commonAncestor = elementChanged ? domUtils.getCommonAncestor(currentElement, prevElement) : null;

Expand Down
17 changes: 17 additions & 0 deletions test/functional/fixtures/regression/gh-8264/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<a href="#" id="link">Click me to remove</a>
<button id="btn">Button</button>

<script>
document.getElementById('link').addEventListener('click', function(event) {
event.preventDefault();
this.remove();
});
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-8264/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('[Regression](GH-8264)', function () {
it('Test should not fails with Uncaught object error on leaveElement when the prevElement is removed from the DOM', function () {
return runTests('testcafe-fixtures/index.js', 'Callsite Issue', { only: 'chrome' });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

fixture('GH-8264 - Callsite Issue')
.page`http://localhost:3000/fixtures/regression/gh-8264/pages/index.html`;

test('Callsite Issue', async t => {
await t
.click('#link')
.click('#btn');
});

0 comments on commit 9e0e580

Please sign in to comment.