Skip to content

Commit

Permalink
fix: unmountComponentAtNode(...): Target container is not a DOM eleme…
Browse files Browse the repository at this point in the history
…ntd fyf (#108)

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

* undid change to see if test fails in CI.

* re-fixed error:  unmountComponentAtNode(...): Target container is not a DOM element.
  • Loading branch information
Robert Williams authored Feb 20, 2020
1 parent fcc75d5 commit c592b0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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('can 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

0 comments on commit c592b0c

Please sign in to comment.