I'm currently trying to test some of my code using jest but for some reason if I send in 4 arguments in the function, it basically shifts the values forward two and the second two are undefined.
This was my test code
const userDistance = require("./avtest");
test("Checks userDistance calculation", () => {
expect(userDistance(1, 1, 4, 5)).toBe(5);
});
Here is the function being tested
function userDistance(x, y, ux, uy) {
let tx = (ux - x) * (ux - x);
let ty = (uy - y) * (uy - y);
return Math.sqrt(ty + tx);
}
module.exports = userDistance;
However, if I do a console.log() for each argument(eg x, y, ux, uy), x prints out as 4, y prints out as 5, and ux and uy are undefined. If I add two more arguments to the function then it works fine (the two added args are also undefined however). I am incredibly confused so any help would be appreciated