import {render, RenderResult} from '@testing-library/react'
import {ReactElement} from 'react'

export class BaseDomHelper {
    // @ts-ignore unknown type
    constructor(private readonly renderer: (refresh: () => void) => ReactElement) {
        function mount() {
            // eslint-disable-next-line prefer-const
            let wrapper: RenderResult;

            const refresh = () => {
                wrapper.rerender(renderer(refresh))
            }

            const result = renderer(refresh)
            wrapper = render(result)
        }

        mount()
    }
}
