Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 36e8976

Browse files
committed
test unmount
1 parent a836bd3 commit 36e8976

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cypress/integration/set-timeout-example/LoadingIndicator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class LoadingIndicator extends Component {
2121
}
2222

2323
componentWillUnmount() {
24+
console.log('componentWillUnmount')
2425
clearTimeout(this._delayTimer);
2526
}
2627

cypress/integration/set-timeout-example/loading-indicator-spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import { unmountComponentAtNode } from "react-dom"
23
import { mount } from "cypress-react-unit-tests";
34
import LoadingIndicator from './LoadingIndicator'
45

@@ -68,8 +69,16 @@ describe('LoadingIndicator', () => {
6869
</LoadingIndicator>
6970
);
7071
cy.tick(2010)
71-
// TODO how to force component unmount?
72-
// TODO confirm @clearTimeout was called
72+
cy.get('#cypress-jsdom').then($el => {
73+
unmountComponentAtNode($el[0])
74+
})
75+
cy.get('@clearTimeout').should('have.been.calledOnce')
7376
});
7477
});
78+
79+
afterEach(() => {
80+
cy.get('#cypress-jsdom').then($el => {
81+
unmountComponentAtNode($el[0])
82+
})
83+
})
7584
});

0 commit comments

Comments
 (0)