Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions packages/driver/cypress/e2e/issues/26206.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// https://github.com/cypress-io/cypress/issues/26206
describe('issue 26206', () => {
beforeEach(() => {
cy.visit('fixtures/issue-26206.html')
})

it('removeAttribute works for non-target attributes after handleInvalidTarget', () => {
// After clicking an anchor with target="_top", the handleInvalidTarget function
// patches the element's removeAttribute. The bug was that removeAttribute
// would not work for attributes other than 'target'.
cy.get('#link').click()
cy.get('#result').should('have.text', 'removed')
})
})
18 changes: 18 additions & 0 deletions packages/driver/cypress/fixtures/issue-26206.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
function removeNonTargetAttribute(e) {
e.target.removeAttribute('data-bar')
document.getElementById('result').innerHTML = e.target.hasAttribute('data-bar') ? 'has-attribute' : 'removed'
}
</script>

<div>
<a href="#" id="link" target="_top" data-bar="baz" onclick="removeNonTargetAttribute(event)">link</a>
<div id="result"></div>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/driver/src/cy/top_attr_guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export function handleInvalidTarget (el: HTMLFormElement | HTMLAnchorElement) {
targetValue = ''

// We're not using `$elements.callNativeMethod` here because it disallows `removeAttribute`.
return removeAttribute.call(this, k)
}
return removeAttribute.call(this, k)
}

if (!targetDescriptor) {
Expand Down
Loading