-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
1 parent
b4cc71d
commit 1c4cff7
Showing
11 changed files
with
244 additions
and
11 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
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,51 @@ | ||
# `.mount() => Self` | ||
|
||
A method that re-mounts the component. This can be used to simulate a component going through | ||
an unmount/mount lifecycle. | ||
|
||
#### Returns | ||
|
||
`ReactWrapper`: Returns itself. | ||
|
||
|
||
|
||
#### Example | ||
|
||
```jsx | ||
const willMount = sinon.spy(); | ||
const didMount = sinon.spy(); | ||
const willUnmount = sinon.spy(); | ||
|
||
class Foo extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.componentWillUnmount = willUnmount; | ||
this.componentWillMount = willMount; | ||
this.componentDidMount = didMount; | ||
} | ||
render() { | ||
return ( | ||
<div className={this.props.id}> | ||
{this.props.id} | ||
</div> | ||
); | ||
} | ||
} | ||
const wrapper = mount(<Foo id="foo" />); | ||
expect(willMount.callCount).to.equal(1); | ||
expect(didMount.callCount).to.equal(1); | ||
expect(willUnmount.callCount).to.equal(0); | ||
wrapper.unmount(); | ||
expect(willMount.callCount).to.equal(1); | ||
expect(didMount.callCount).to.equal(1); | ||
expect(willUnmount.callCount).to.equal(1); | ||
wrapper.mount(); | ||
expect(willMount.callCount).to.equal(2); | ||
expect(didMount.callCount).to.equal(2); | ||
expect(willUnmount.callCount).to.equal(1); | ||
``` | ||
|
||
|
||
#### Related Methods | ||
|
||
- [`.unmount() => Self`](unmount.md) |
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,47 @@ | ||
# `.unmount() => Self` | ||
|
||
A method that re-mounts the component. This can be used to simulate a component going through | ||
an unmount/mount lifecycle. | ||
|
||
#### Returns | ||
|
||
`ReactWrapper`: Returns itself. | ||
|
||
|
||
|
||
#### Example | ||
|
||
```jsx | ||
const willMount = sinon.spy(); | ||
const didMount = sinon.spy(); | ||
const willUnmount = sinon.spy(); | ||
|
||
class Foo extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.componentWillUnmount = willUnmount; | ||
this.componentWillMount = willMount; | ||
this.componentDidMount = didMount; | ||
} | ||
render() { | ||
return ( | ||
<div className={this.props.id}> | ||
{this.props.id} | ||
</div> | ||
); | ||
} | ||
} | ||
const wrapper = mount(<Foo id="foo" />); | ||
expect(willMount.callCount).to.equal(1); | ||
expect(didMount.callCount).to.equal(1); | ||
expect(willUnmount.callCount).to.equal(0); | ||
wrapper.unmount(); | ||
expect(willMount.callCount).to.equal(1); | ||
expect(didMount.callCount).to.equal(1); | ||
expect(willUnmount.callCount).to.equal(1); | ||
``` | ||
|
||
|
||
#### Related Methods | ||
|
||
- [`.mount() => Self`](mount.md) |
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
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
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
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
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
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
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
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,22 @@ | ||
if (!global.document) { | ||
try { | ||
const jsdom = require('jsdom').jsdom; // could throw | ||
|
||
const exposedProperties = ['window', 'navigator', 'document']; | ||
|
||
global.document = jsdom(''); | ||
global.window = document.defaultView; | ||
Object.keys(document.defaultView).forEach((property) => { | ||
if (typeof global[property] === 'undefined') { | ||
exposedProperties.push(property); | ||
global[property] = document.defaultView[property]; | ||
} | ||
}); | ||
|
||
global.navigator = { | ||
userAgent: 'node.js', | ||
}; | ||
} catch (e) { | ||
// jsdom is not supported... | ||
} | ||
} |