react-performance-testing
react-performance-testing copied to clipboard
[react-performance-testing] You have anonymous component. If your component don't have display name, we can not set property to renderCount.current
Warning shows even if displayName explicitly set already.
describe('KeyboardAccessibilityContext - rerenders', () => {
it('render count should be one', async () => {
function MockContextConsumerComponent() {
const { setVisible, visible } = useKeyboardAccessibilityContext()
return (
<Button
title="Test btn"
testID="btn"
onPress={() => setVisible(!visible)}
/>
)
}
MockContextConsumerComponent.displayName = 'MockContextConsumerComponent'
const useKeyboardAccessibilityHookReturnValue = {
setVisible: jest.fn(() => null),
visible: false,
}
function MockContextScenario() {
return (
<KeyboardAccessibilityProvider
useKeyboardAccessibilityHook={() =>
useKeyboardAccessibilityHookReturnValue
}
>
<MockContextConsumerComponent />
</KeyboardAccessibilityProvider>
)
}
MockContextScenario.displayName = 'MockContextScenario'
const { renderCount } = perf(React)
const { getByTestId } = render(<MockContextScenario />)
fireEvent.press(getByTestId('btn'))
await wait(() => {
expect(renderCount.current.MockContextScenario.value).toBe(1)
})
})
})
Could you create codesandbox?
okay