How to mock different scenarios with Detox? #2935
-
A question on how I would mock different scenarios, say I wanted to mock an image picker:
I can write a mock of my image picker which returns a PNG file path in my detox tests, but how would I configure variable behaviour per test run? i.e. say I wanted to test all the three scenarios above with the same mock file. (or different mock files). It seems as if this is not supported. If this isn't supported, what would be the road to supporting something like this? Are other people interested in this feature? It would need to be controlled with environment variables, as the mock code is setup at compile time, not runtime. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hey @lukebrandonfarrell, that's a very interesting topic. In general, the recommended mocking technique is described in our mocking guide. As for the use case you're describing, it sounds to me that it aligns with the technique pretty well. Largely, I think these principles sum it up:
Does that roughly solve you case? |
Beta Was this translation helpful? Give feedback.
-
I have a question: Can i put the ImagePickerProvider.ts and ImagePickerProvider.e2e.ts files used for mocking in another directory like e2e/mocks? If yes, what do i then need to change to my configuration? i would like to know this because putting all these files in the root of our project is not ideal. |
Beta Was this translation helpful? Give feedback.
Hey @lukebrandonfarrell, that's a very interesting topic.
Mocking is not something Detox is suppose to support per se (no Detox feature is associated with that, explicitly). However, it is something so fundamental in testing, that we care about helping out with it as if was a core feature.
In general, the recommended mocking technique is described in our mocking guide. As for the use case you're describing, it sounds to me that it aligns with the technique pretty well. Largely, I think these principles sum it up:
ImagePicker.jsx
-- create a mock equivalent in a file calledImagePicker.e2e.jsx
.