import { render } from '@testing-library/react-native'
import React from 'react'
import { Text } from 'react-native'
import { Log } from '../../../utils/native_adapters/configuration'
import { ComponentErrorBoundary } from '../component_error_boundary'
function Boom({ thrown }: { thrown: unknown }): React.ReactElement {
throw thrown
}
describe('ComponentErrorBoundary', () => {
let reportError: jest.SpyInstance
let consoleError: jest.SpyInstance
beforeEach(() => {
reportError = jest.spyOn(Log, 'reportError').mockImplementation(() => {})
consoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
})
afterEach(() => {
reportError.mockRestore()
consoleError.mockRestore()
})
it('defaults the reporter scope to "component" and renders nothing on catch', () => {
const { toJSON } = render(
)
expect(toJSON()).toBeNull()
expect(reportError.mock.calls[0][1]).toMatchObject({ scope: 'component' })
})
it('lets callers override the defaults', () => {
const { getByText } = render(
overridden}>
)
expect(getByText('overridden')).toBeTruthy()
expect(reportError.mock.calls[0][1]).toMatchObject({ scope: 'screen' })
})
})