I am using “fetch-vcr” pacakage in my React Native App to mock the api response automatically.
text
i have done the setup as documented. but when i am running my e2e tests and my api is getting called i am facing issue that ” [Error: fetch-vcr: Saving Fixture files is not supported in the browser yet]”
but when i am calling any api through the test case like below
it('should fetch mock API data', async () => {
try {
console.log('Starting API fetch test');
const sessionId =
'123456abcdefgzxcvbnm';
const response = await fetch(
'https://qa.example.com/api/?page=1',
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
Cookie: `_session_id=${sessionId}`,
},
},
);
const data = await response.json();
} catch (error) {
console.error('Error in fetch test:', error);
throw error;
}
});
Then my mocked data file is generating and getting stored in my ./e2e/_fixtures file
I have done the below setup
e2e/fetchVCRSetup.js
import { default as fetchVCR } from 'fetch-vcr';
fetchVCR.configure({
fixturePath: './e2e/_fixtures',
mode: 'record',
node: true,
});
global.fetch = fetchVCR;
e2e/jest.config.js
module.exports = {
setupFilesAfterEnv: ['<rootDir>/e2e/fetchVCRSetup.js'],
};
How to generate mocked data file automatically ?
Whenever i am running my e2e tests and my api is getting called and i can see the response while running tests. but the mocked file is not generating
shubham surve is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.