I am using React Native and I am trying to mock an Axios request by returning the contents of a JSON file to my API call for testing purposes. However, I am not able to executeaxios.get('text.json')
as it only allows URL input.
I am retrieving my relative path from a .env config file, and I have tried using require(myPathVariable) but it does not allow me to use relative path.
I have also tried using fs.readFile('../mock/test.json')
and require()
but it does not allow relative path to my text.json file. so I am wondering how to get the working directory so that I can concatenate it to become an absolute path.
I am open to alternative ways of implementing this. I thought this would be easy to implement but apparently react native has many restrictions that I didn't thought I would encounter. I am onto this for a week now and I am at my wits end. Any help would be greatly appreciated!!