I am trying to make an API call, which works and this is shown by my console.log as this prints out what I am looking for. However, when I try to return the same value it doesn't return what I want / what was expected:
Function:
export async function TeamSquad({URL, TeamID}) {
try {
// StringCheck - Checks TeamID is a string
StringCheck(TeamID);
const apiResponse = await axios(paramOptions(URL, {
team: TeamID,
}));
const response = apiResponse.data.response;
// TeamSquadBasic - Fills an object with objects
const Squad = TeamSquadBasicInfo(response);
console.log(Squad["0"]) // This works as expected
// Count / Check position count
// PlayersInPosition(Squad);
return Squad["0"]; // This doesn't work as expected
} catch (error) {
console.error(error);
}
}
How I call the function (For example purposes):
test("Squad Line Up", async () => {
const Lineup = await TeamSquad({
URL: 'https://api-football-v1.p.rapidapi.com/v3/squads',
TeamID: '33'
});
expect(Lineup).toEqual(LineupHeaton); // LineupHeaton is Squad["0"] hardcoded
});
The result of Squad["0"]:
{ "Plays For": "Manchester United", "name": "T. Heaton", "age": 37, "number": 22, "position": "Goalkeeper", "photo": "https://media-3.api-sports.io/football/players/2931.png" }
When I console.log this the result comes out like ^, but when I try to return this it comes out like:
{"_h": 0, "_i": 0, "_j": null, "_k": null}