[Management] Prevent react warnings in index pattern creation (#16520)

* Prevent react warnings

* Use common function, PR feedback
This commit is contained in:
Chris Roberson 2018-02-08 13:48:44 -05:00 committed by GitHub
parent c25548566f
commit b69947781f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -7,6 +7,7 @@ const { renderStepIndexPattern, destroyStepIndexPattern } = require('../index');
describe('StepIndexPatternRender', () => {
beforeEach(() => {
jest.spyOn(document, 'getElementById').mockImplementation(() => ({}));
render.mockClear();
unmountComponentAtNode.mockClear();
});

View file

@ -2,6 +2,10 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { StepIndexPattern } from './step_index_pattern';
function getNode(domElementId) {
return document.getElementById(domElementId);
}
export function renderStepIndexPattern(
domElementId,
allIndices,
@ -10,6 +14,11 @@ export function renderStepIndexPattern(
esService,
goToNextStep,
) {
const node = getNode(domElementId);
if (!node) {
return;
}
render(
<StepIndexPattern
allIndices={allIndices}
@ -23,5 +32,10 @@ export function renderStepIndexPattern(
}
export function destroyStepIndexPattern(domElementId) {
unmountComponentAtNode(document.getElementById(domElementId));
const node = getNode(domElementId);
if (!node) {
return;
}
unmountComponentAtNode(node);
}