Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
React.useEffect(() => {
// Create empty fixture state
if (!fixtureState.props && elPaths.length === 0) {
// Make sure not to override any (currently pending) fixture state props
setFixtureState(prevFs => ({ ...prevFs, props: prevFs.props || [] }));
return;
}
// Remove fixture state for removed child elements (likely via HMR)
// FIXME: Also invalidate fixture state at this element path if the
// component type of the corresponding element changed
const fsProps = getFixtureStateProps(fixtureState, decoratorId);
fsProps.forEach(({ elementId }) => {
if (elPaths.indexOf(elementId.elPath) === -1) {
setFixtureState(prevFs => ({
...prevFs,
props: removeFixtureStateProps(fixtureState, elementId)
}));
}
});
elPaths.forEach(elPath => {
const childEl = getExpectedElementAtPath(fixture, elPath);
const elementId = { decoratorId, elPath };
// Component fixture state can be provided before the fixture mounts (eg.
// a previous snapshot of a fixture state or the current fixture state
// from another renderer)
if (!findFixtureStateProps(fixtureState, elementId)) {
setFixtureState(fixtureState => {
const instanceProps = {
instanceId,
componentName,
renderKey: DEFAULT_RENDER_KEY,
values: extractValuesFromObject(children.props)
};
return {
props: replaceOrAddItem(
getFixtureStateProps(fixtureState),
props => props.instanceId === instanceId,
instanceProps
)
};
});
}
setFixtureState(fixtureState => {
return {
props: removeItemMatch(
getFixtureStateProps(fixtureState),
props => props.instanceId === instanceId
)
};
});
}