Skip to content

Commit

Permalink
fix(basemanager): Replace remove method that is unsupported in IE11 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Feb 3, 2021
1 parent 1920e3a commit f0fd58e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/common/BaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export default class BaseManager implements Manager {
destroy(): void {
ReactDOM.unmountComponentAtNode(this.reactEl);

this.reactEl.remove();
const parentEl = this.reactEl.parentNode;
if (parentEl) {
parentEl.removeChild(this.reactEl);
}
}

exists(parentEl: HTMLElement): boolean {
Expand Down
13 changes: 13 additions & 0 deletions src/common/__tests__/BaseManager-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as ReactDOM from 'react-dom';
import BaseManager, { Options, Props } from '../BaseManager';

jest.mock('react-dom');
class TestBaseManager extends BaseManager {
// eslint-disable-next-line @typescript-eslint/no-empty-function
decorate(): void {}
Expand Down Expand Up @@ -38,4 +40,15 @@ describe('BaseManager', () => {
expect(wrapper.reactEl.getAttribute('data-resin-foo')).toBe('bar');
});
});

describe('destroy()', () => {
test('should unmount and remove node', () => {
const removeChildSpy = jest.spyOn(rootEl, 'removeChild');
const wrapper = getWrapper();
wrapper.destroy();

expect(ReactDOM.unmountComponentAtNode).toHaveBeenCalledWith(wrapper.reactEl);
expect(removeChildSpy).toHaveBeenCalledWith(wrapper.reactEl);
});
});
});

0 comments on commit f0fd58e

Please sign in to comment.