-
-
Notifications
You must be signed in to change notification settings - Fork 158
Added contentWillUnmount prop to call before the Contents unmounts. #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
60a04d6
d7bceae
08a9e14
b15f3c8
7d4418a
b5099c7
e1fa1b4
9bd4b98
58d01e4
84443a4
208e7a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ReactDOM from 'react-dom'; | ||
import ReactTestUtils from 'react-dom/test-utils'; | ||
|
@@ -313,6 +313,63 @@ describe('The Frame Component', () => { | |
); | ||
}); | ||
|
||
it('should call contentWillUnmount on unmount', done => { | ||
div = document.body.appendChild(document.createElement('div')); | ||
const willUnmount = sinon.spy(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this is called but this test doesn't check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I just need to check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated this test. But, the test is failing. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so i think what we're doing here is actually the wrong thing, the issue is about having a callback when the So I think what we need is a bit simpler instead of passing the Then you can just test it like this: it('should call contentWillUnmount on unmount', done => {
div = document.body.appendChild(document.createElement('div'));
const willUnmount = sinon.spy();
const frame = ReactDOM.render(
<Frame frameWillUnmount={willUnmount} />,
div
);
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(frame).parentNode);
expect(willUnmount.callCount).to.equal(1, 'expected 1 willUnmount');
done();
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. But still There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah ok having though on this more I think what you have is useful in two instances of changing the iframe contents as well as unmounting the entire Frame too. I honestly have no idea why this isn't firing in test env, if you run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried with |
||
|
||
function Parent() { | ||
const [isClosed, setClosed] = React.useState(false); | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
setClosed(true); | ||
}, 1500); | ||
}, []); | ||
|
||
if (!isClosed) { | ||
return ( | ||
<Frame | ||
contentWillUnmount={() => { | ||
willUnmount(); | ||
done(); | ||
}} | ||
/> | ||
); | ||
} | ||
return null; | ||
} | ||
ReactDOM.render(<Parent />, div); | ||
}); | ||
|
||
it('should not error when null is passed in contentWillUnmount', () => { | ||
Reflex-Gravity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
div = document.body.appendChild(document.createElement('div')); | ||
ReactDOM.render(<Frame contentWillUnmount={null} />, div); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also these tests should assert something? |
||
}); | ||
|
||
it('should not error when contentWillUnmount is not passed', done => { | ||
div = document.body.appendChild(document.createElement('div')); | ||
const didUpdate = sinon.spy(); | ||
const didMount = sinon.spy(); | ||
const frame = ReactDOM.render( | ||
<Frame | ||
contentDidUpdate={didUpdate} | ||
contentDidMount={() => { | ||
didMount(); | ||
frame.setState({ foo: 'bar' }, () => { | ||
expect(didMount.callCount).to.equal(1, 'expected 1 didMount'); | ||
expect(didUpdate.callCount).to.equal(1, 'expected 1 didUpdate'); | ||
frame.setState({ foo: 'gah' }, () => { | ||
expect(didMount.callCount).to.equal(1, 'expected 1 didMount'); | ||
expect(didUpdate.callCount).to.equal(2, 'expected 2 didUpdate'); | ||
done(); | ||
}); | ||
}); | ||
}} | ||
/>, | ||
div | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here nothing is asserted? |
||
}); | ||
|
||
it('should return first child element of the `body` on call to `this.getMountTarget()` if `props.mountTarget` was not passed in', () => { | ||
div = document.body.appendChild(document.createElement('div')); | ||
|
||
|
@@ -424,7 +481,7 @@ describe('The Frame Component', () => { | |
contentDidMount={() => { | ||
const iframes = ReactDOM.findDOMNode(div).querySelectorAll('iframe'); | ||
|
||
expect(iframes[0].contentDocument.body.children.length).to.equal(1); | ||
expect(iframes[0].contentDocument.body.children.length).to.equal(1); | ||
expect(iframes[0].contentDocument.body.children.length).to.equal(1); | ||
done(); | ||
}} | ||
|
Uh oh!
There was an error while loading. Please reload this page.