reassure icon indicating copy to clipboard operation
reassure copied to clipboard

[FEATURE] Improve `scenario` type def and export `MeasureOptions` from `reassure`

Open sbalay opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. Not really a problem but when declaring a scenario and using screen as the scenario param instead of importing it from testing-library, I would like to have proper types for it.

I tried:

import { measurePerformance, MeasureOptions } from 'reassure';
import { fireEvent } from '@testing-library/react-native';
import { ComponentUnderTest } from './ComponentUnderTest';

test('Test with scenario', async () => {
  const scenario: MeasureOptions['scenario'] = async (screen) => {
    fireEvent.press(screen.getByText('Go'));
    await screen.findByText('Done');
  };

  await measureRenders(<ComponentUnderTest />, { scenario });
});

But MeasureOptions is not available for me to import, and even if it was, I saw the types for scenario just use any for the screen:

export interface MeasureOptions {
  runs?: number;
  warmupRuns?: number;
  wrapper?: React.ComponentType<{ children: React.ReactElement }>;
  scenario?: (screen: any) => Promise<any>;
}

Describe the solution you'd like I can import MeasureOptions and scenario has proper types for the screen param

Describe alternatives you've considered none

Additional context I guess this is not a huge problem since it only affects codebases relying on old versions of testing-library where you can not import screen from there... still... seems like a quick fix and a nice improvement for reassure

Using v0.10.2

sbalay avatar Jan 28 '24 19:01 sbalay

Seems that the export has already been tackled here but they type still relies on any

sbalay avatar Jan 28 '24 19:01 sbalay

You could explicitly type screen as RenderResult from RNTL. The reason why Reassure uses any is that you can also use it with React Testing Library, which has a different type.

https://github.com/callstack/react-native-testing-library/blob/a282d1ecdda4c7141f38b13d38105e0d16d67c16/src/pure.ts#L18

mdjastrzebski avatar Jan 29 '24 12:01 mdjastrzebski

Closing as solved by workaround.

mdjastrzebski avatar Mar 08 '24 12:03 mdjastrzebski