Skip to content

Instantly share code, notes, and snippets.

@scottmries
Last active May 10, 2024 13:40
Show Gist options
  • Save scottmries/4894634effe33d05fb8c58b0f7d0fc86 to your computer and use it in GitHub Desktop.
Save scottmries/4894634effe33d05fb8c58b0f7d0fc86 to your computer and use it in GitHub Desktop.
import { useEffect, useState } from 'react';
function App() {
const [on, setOn] = useState(false);
const [remounts, setRemounts] = useState(0);
const [showDisappearingButton, setShowDisappearingButton] = useState(true);
useEffect(() => {
let interval, disappearingInterval, appearingInterval
if (remounts < 1000) {
interval = setInterval(() => {
setOn(!on);
setRemounts(remounts + 1);
}, 0);
setTimeout(() => {
disappearingInterval = setInterval(() => {
setShowDisappearingButton(false);
}, 10);
}, 1);
appearingInterval = setInterval(() => {
setShowDisappearingButton(true);
}, 3999)
}
return () => {
clearInterval(interval);
clearInterval(disappearingInterval);
clearInterval(appearingInterval);
}
});
return (
<div className="App">
{ showDisappearingButton ? (
<button id="disappearing">disappearing button</button>
) : null
}
{on ? (
<div id="parent">
<button id="remounting">remounting</button>
<button className="remounting" id="remounting-2">remounting</button>
<button className="remounting" id="remounting-3">remounting</button>
<input type="checkbox" className="remounting" id="remounting-4"></input>
<input type="checkbox" className="remounting" id="remounting-5"></input>
</div>
) : null }
{!on ? (
<div id="parent">
<button id="remounting">remounting</button>
<button className="remounting" id="remounting-2">remounting</button>
<button className="remounting" id="remounting-3">remounting</button>
<input type="checkbox" className="remounting" id="remounting-4"></input>
<input type="checkbox" className="remounting" id="remounting-5"></input>
</div>
) : null }
<button id="not-remounting">not remounting</button>
</div>
);
}
export default App;
CypressError: `cy.then()` timed out after waiting `4000ms`.
Your callback function returned a promise that never resolved.
The callback function was:
() => originalFn(...args)
https://on.cypress.io/then
at <unknown> (http://localhost:6543/__cypress/runner/cypress_runner.js:118353:75)
at tryCatcher (http://localhost:6543/__cypress/runner/cypress_runner.js:1807:23)
at <unknown> (http://localhost:6543/__cypress/runner/cypress_runner.js:4186:41)
at tryCatcher (http://localhost:6543/__cypress/runner/cypress_runner.js:1807:23)
at Promise._settlePromiseFromHandler (http://localhost:6543/__cypress/runner/cypress_runner.js:1519:31)
at Promise._settlePromise (http://localhost:6543/__cypress/runner/cypress_runner.js:1576:18)
at Promise._settlePromise0 (http://localhost:6543/__cypress/runner/cypress_runner.js:1621:10)
at Promise._settlePromises (http://localhost:6543/__cypress/runner/cypress_runner.js:1697:18)
at _drainQueueStep (http://localhost:6543/__cypress/runner/cypress_runner.js:2407:12)
at _drainQueue (http://localhost:6543/__cypress/runner/cypress_runner.js:2400:9)
at Async._drainQueues (http://localhost:6543/__cypress/runner/cypress_runner.js:2416:5)
at Async.drainQueues (http://localhost:6543/__cypress/runner/cypress_runner.js:2286:14)
From Your Spec Code:
at Context.eval (webpack:///../src/cypressCommands.ts:123:7)
describe('test', () => {
it("doesn't error when no remounting", () => {
cy.visit('/')
.get('button#not-remounting')
.click();
});
it('errors with a single selected remounting element', () => {
cy.visit('/')
.get('button#remounting-3')
.click();
});
it('errors with multiple selected remounting elements', () => {
cy.visit('/')
.get('button.remounting')
.click({multiple: true});
});
it('errors with multiple selected remounting elements and selectors', () => {
cy.visit('/')
.get('#remounting-2, #remounting-3')
.click({multiple: true});
});
it('errors when a Cypress command that handles multiple DOM elements tries to handle multiple remounting elements', () => {
cy.visit('/')
.get('input.remounting')
.click({multiple: true})
});
it('(sometimes) errors from Axe when an element is detached and not reattached with the same selector', () => {
cy.visit('/')
.get('button#disappearing')
.click()
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment