I'm testing login in react, the test is passing but this error is happening
Error: Cross origin http://localhost forbidden
I already searched and didn't find anything about it in react, only in node
it('make login', async () => {
server.use(
rest.post('http://localhost:2001/backend_ihm/auth/login', async (req, res, ctx) => {
const { username, password, keepLogin } = await req.json();
return res(
ctx.json(user)
);
}));
const { getByTestId } = render(
<Router>
<AuthProvider>
<Login />
</AuthProvider>
</Router>
);
await screen.getByTestId('loading');
await waitForElementToBeRemoved(() => screen.getByTestId(/loading/i));
await screen.getByTestId('login-container');
const buttonLogin = getByTestId('button-login');
const checkboxKeepLogin = getByTestId('f');
const { inputUsername, inputPassword } = setup();
fireEvent.change(inputUsername, { target: { value: 'iplabs' } });
fireEvent.change(inputPassword, { target: { value: '123' } });
fireEvent.click(checkboxKeepLogin);
fireEvent.click(buttonLogin);
});
I added this code to my api file
axios.defaults.adapter = require('axios/lib/adapters/http');