Skip to content
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

Fixed error where crash will happen if fired twice in a row. #108

Merged
merged 3 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export default function withReactContent (ParentSwal) {
const superOnDestroy = params.onDestroy
params.onDestroy = (element) => {
superOnDestroy(element)
ReactDOM.unmountComponentAtNode(domElement)
if (domElement) {
ReactDOM.unmountComponentAtNode(domElement)
}
}
}
})
Expand Down
19 changes: 19 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ describe('integration', () => {
},
})
})
it('fire twice without crashing', async () => {
await cleanSwalState()
const MySwal = withReactContent(SwalWithoutAnimation)
MySwal.fire({
title: <span>React element</span>,
footer: 'plain text'
})
await MySwal.fire({
title: <span>React element</span>,
footer: 'plain text',
onOpen: () => {
expect(MySwal.getTitle().innerHTML).toEqual(
'<span>React element</span>',
)
expect(MySwal.getFooter().innerHTML).toEqual('plain text')
MySwal.clickConfirm()
},
})
})
it('returns a class with the same instance & static properties as Swal', async () => {
const MySwal = withReactContent(Swal)
Object.keys(Swal).forEach(key => {
Expand Down