I'm pretty new to Jest and I completed testing all the components of my project and now when I wanted to test the axios call I'm facing this erro.
My test
import addPatients from '../ApiCalls/ApiCalls'
test('patient data is posted', () => {
addPatients(data).then(response=>{
console.log(response.data)
})
});
Api.js
export function addPatients (state){
console.log(state)
try {
const response = axios.post('/addpatient', state);
// add patient calls rails controller, basically I'm using react on rails
console.log(response);
return response;
}
catch (error) {
console.log(error);
}
};
The project is working perfectly fine, but I'm not able to test that. When I run this test, I get the following error
TypeError: (0 , _ApiCalls.default) is not a function
22 | test('patient data is posted', () => {
23 |
> 24 | addPatients(data).then(response=>{
| ^
25 | console.log(response.data)
26 |
27 | })
at Object.<anonymous> (app/javascript/components/__tests__/Api.test.js:24:5)
I tried with :
- Adding export default to the function
- Adding async and await
Trying from couple of days,nothing seems to work. Please guide me on testing this, as only work pending is test.
import { addPatients } from ...
. – Estus Flask