mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
fix(collections): correct error class when chunk()
throws (#4682)
refactor(collections): correct error class when `chunk()` throws
This commit is contained in:
parent
1a0907eb53
commit
e7b2ca69ee
@ -39,7 +39,7 @@
|
||||
*/
|
||||
export function chunk<T>(array: readonly T[], size: number): T[][] {
|
||||
if (size <= 0 || !Number.isInteger(size)) {
|
||||
throw new Error(
|
||||
throw new RangeError(
|
||||
`Expected size to be an integer greater than 0 but found ${size}`,
|
||||
);
|
||||
}
|
||||
|
@ -27,11 +27,31 @@ Deno.test({
|
||||
Deno.test({
|
||||
name: "chunk() throws on non naturals",
|
||||
fn() {
|
||||
assertThrows(() => chunk([], +.5));
|
||||
assertThrows(() => chunk([], -4.7));
|
||||
assertThrows(() => chunk([], -2));
|
||||
assertThrows(() => chunk([], +0));
|
||||
assertThrows(() => chunk([], -0));
|
||||
assertThrows(
|
||||
() => chunk([], +.5),
|
||||
RangeError,
|
||||
"Expected size to be an integer greater than 0 but found 0.5",
|
||||
);
|
||||
assertThrows(
|
||||
() => chunk([], -4.7),
|
||||
RangeError,
|
||||
"Expected size to be an integer greater than 0 but found -4.7",
|
||||
);
|
||||
assertThrows(
|
||||
() => chunk([], -2),
|
||||
RangeError,
|
||||
"Expected size to be an integer greater than 0 but found -2",
|
||||
);
|
||||
assertThrows(
|
||||
() => chunk([], +0),
|
||||
RangeError,
|
||||
"Expected size to be an integer greater than 0 but found 0",
|
||||
);
|
||||
assertThrows(
|
||||
() => chunk([], -0),
|
||||
RangeError,
|
||||
"Expected size to be an integer greater than 0 but found 0",
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user