This repository has been archived by the owner on Mar 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# unmount | ||
|
||
If you need to test what the component is doing when it is being unmounted, use `unmount` function. | ||
|
||
```js | ||
import { mount, unmount } from 'cypress-react-unit-test' | ||
it('calls unmount prop', () => { | ||
mount(...) | ||
// cy commands | ||
// now let's unmount | ||
cy.then(unmount) | ||
|
||
// confirm the component has been unmounted | ||
// and performed everything needed in its | ||
// componentWillUnmount method | ||
}) | ||
``` | ||
|
||
See [unmount-spec.js](unmount-spec.js) and [comp-spec.js](comp-spec.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// <reference types="cypress" /> | ||
import React, { Component } from 'react' | ||
import { mount, unmount } from 'cypress-react-unit-test' | ||
|
||
class Comp extends Component { | ||
componentWillUnmount() { | ||
// simply calls the prop | ||
this.props.onUnmount() | ||
} | ||
|
||
render() { | ||
return <div>My component</div> | ||
} | ||
} | ||
|
||
describe('Comp with componentWillUnmount', () => { | ||
it('calls the prop', () => { | ||
mount(<Comp onUnmount={cy.stub().as('onUnmount')} />) | ||
cy.contains('My component') | ||
|
||
// after we have confirmed the component exists | ||
// we can remove it asynchronously | ||
cy.then(() => { | ||
// now unmount the mounted component | ||
unmount() | ||
}) | ||
|
||
// the component is gone from the DOM | ||
cy.contains('My component').should('not.exist') | ||
// the component has called the prop on unmount | ||
cy.get('@onUnmount').should('have.been.calledOnce') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters