I am facing an error using JEST with Express while I execute my test with npm run test.
console.error
Error: Cross origin http://localhost forbidden
I've seen similar post like CORS error - Error: Cross origin http://localhost forbidden... without working answers
Here is my test :
const app = require('../app');
const request = require("supertest");
const enjoyService = require('../services/enjoy.service');
describe('/enjoy', () => {
describe("/cinema/:city", () => {
test('Status is OK', () => {
return enjoyService.listCinema("nantes").then(res => {
expect(res.data.status).toBe('OK');
});
});
test('Status is 404', () => {
return enjoyService.listCinema("X Æ A-XII").catch(err => {
expect(err.name).toBe("Error");
});
});
});
});
And the enjoy.service used bellow
const axios = require('axios'),
googleBaseURL = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=";
function listCinema(city) {
return axios.get(googleBaseURL + city + '&type=cinema&key=' + process.env.GOOGLE_API)
}