Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sbalay opened this issue Jan 28, 2024 · 3 comments
Closed

Comments

@sbalay
Copy link

sbalay commented Jan 28, 2024

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
Copy link
Author

sbalay commented Jan 28, 2024

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

@mdjastrzebski
Copy link
Member

mdjastrzebski commented Jan 29, 2024

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
Copy link
Member

Closing as solved by workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants