Closed henrythasler closed 2 years ago
@matafokka: This is your modification. Maybe you have an idea why this happens.
ps: I have reverted the change for now
The test is wrong. This test should be right:
it("1D-Array - unknown Object (string instead of number)", function () {
try {
latlngExpressionArraytoLatLngArray([{ lat: Berlin.lat, lng: "matafokka" } as any]);
} catch (e) {
expect(e).to.be.an("Error");
expect(e.message).to.have.match(/Unknown object found/);
}
});
I have no experience with Jest, so I took one of your other working tests and modified it.
Moreover, in browser it throws for both 2D and 1D array with the same { lat: Berlin.lat, lng: "matafokka"}
object.
No, sorry, your test seems right, let me take a deeper look
Fixed it. Looks not as good as I wanted initially, but seems to get the job done. Passes both old and new tests.
export function latlngExpressionArraytoLatLngArray(input: L.LatLngExpression[] | L.LatLngExpression[][]): L.LatLng[][] {
let latlng: L.LatLng[][] = [],
iterateOver = (instanceOfLatLngExpression(input[0]) ? [input] : input),
error = new Error("L.LatLngExpression[] | L.LatLngExpression[][] expected. Unknown object found.");
if (!(iterateOver instanceof Array)) {
throw error;
}
for (let group of iterateOver as L.LatLngExpression[][]) {
if (!(group instanceof Array)) {
throw error;
}
let sub = [];
for (let point of group) {
if (!instanceOfLatLngExpression(point)) {
throw error;
}
sub.push(latlngExpressiontoLatLng(point));
}
latlng.push(sub);
}
return latlng;
}
see PR #83
Test
latlngExpressionArraytoLatLngArray › 1D-Array - unknown Object (string instead of number)
: