react-performance-testing icon indicating copy to clipboard operation
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

Open jojonarte opened this issue 4 years ago • 2 comments

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)
      })
    })
  })

jojonarte avatar Oct 02 '21 08:10 jojonarte

Could you create codesandbox?

keiya01 avatar Oct 11 '21 05:10 keiya01

okay

jojonarte avatar Oct 11 '21 11:10 jojonarte