While executing the test cases, the test case is failing with error:
FAIL src/tests/auth/SignIn.test.js (6.321 s)
● SignIn Component › dispatches signIn action on form submission
Actions must be plain objects. Use custom middleware for async actions.
31 | const handleSubmit = (e) => {
32 | e.preventDefault();
> 33 | dispatch(signIn(creds.email, creds.password));
| ^
34 | setCreds({ email: "", password: "" });
35 | };
36 |
My testing structure looks like this:
In SignIn.jsx, the error is coming at:
const handleSubmit = (e) => {
e.preventDefault();
dispatch(signIn(creds.email, creds.password));
setCreds({ email: "", password: "" });
};
The signIn() method code is as follows:
export const signIn = (email, password) => {
return (dispatch) => {
axios
.post(`${url}/signin`, { email, password })
.then((token) => {
localStorage.setItem("token", token.data);
dispatch({
type: "SIGN_IN",
token: token.data,
});
})
.catch((error) => {
console.log(error.response);
toast.error(error.response?.data, {
position: toast.POSITION.BOTTOM_RIGHT,
});
});
};
};
Can anybody guide how to solve this?
I have tried solving via other stackoverflow threads, but not helped. How to solve this via jest, i need help on that