FormidableLabs / react-native-owl

Visual regression testing library for React Native that enables developers to introduce visual regression tests to their apps.
https://formidable.com/open-source/react-native-owl/
MIT License
635 stars 27 forks source link

Abilities for mocking the service data, so that the screens can be consistently tested for changes #158

Open g-tiwari opened 1 year ago

g-tiwari commented 1 year ago

Is there any capability exist to mock the backend test data and then load my page with that data. As of now for some of my screens the data is dynamic and React native owl end up showing that as bug for every test run. Are we planning to add support to add mocking ?

kevindice commented 1 year ago

Hi @g-tiwari, I might recommend a metro config override where you could swap out a real module with a mocked one containing a data fixture.

For example:

This would be the real file myApi.ts

export const getProfile = () => fetch('https://myapi.com/me');

And this would be your mock myApi.e2emock.ts:

export Promise.resolved({ username: 'asdf' });

Your metro override would prioritize one file extension over another depending on whether an environment variable is set or not.

IMO, support for mocking like this should fall outside of the scope of Owl here, but there are definitely ways to achieve what you're looking for.