You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I function working smoothly and without any error, also the comment log above works fine, but when it come to run the test it always complained about reading undefined from ".data"
test:
import axios from 'axios';
import { updateCountryLanguage } from './A_9';
jest.mock('axios');
describe('updateCountryLanguage', () => {
it('should add a new language to a country successfully', async () => {
const countryName = 'Tunisia';
const newLanguage = 'French';
axios.get.mockImplementationOnce(() => Promise.resolve({data: {
languages: ['Arabic']
}}));
axios.put.mockResolvedValue({
data: {
languages: ['French']
}
});
await updateCountryLanguage(countryName, newLanguage);
expect(axios.put).toHaveBeenCalledWith(
`http://localhost:3000/countries/${countryName}`,
expect.objectContaining({
languages: expect.arrayContaining(['Arabic', 'French'])
})
);
});
});
I don't understand why it failed, and the reason behind
Expected behavior
run test successfully
Actual behavior
Cannot read properties of undefined (reading 'data')
Additional context
No response
Environment
Linux 20.04
The text was updated successfully, but these errors were encountered:
Version
29
Steps to reproduce
I wrote an unit test to test the below function using axios to fetch data ( I use a json file to mock server request/response):
I function working smoothly and without any error, also the comment log above works fine, but when it come to run the test it always complained about reading undefined from ".data"
test:
I don't understand why it failed, and the reason behind
Expected behavior
run test successfully
Actual behavior
Cannot read properties of undefined (reading 'data')
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: