mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-10-28 23:57:17 +09:00
41 lines
796 B
TypeScript
41 lines
796 B
TypeScript
import { expect, test } from "vitest";
|
|
import { removeByMutable, repeatUntil } from "./array-utils";
|
|
|
|
test("removeByMutable", () => {
|
|
const array = [
|
|
{ param: 1 },
|
|
{ param: 2 },
|
|
{ param: 3 },
|
|
{ param: 4 },
|
|
{ param: 5 },
|
|
{ param: 6 },
|
|
];
|
|
removeByMutable(array, (item) => item.param % 2 === 1);
|
|
expect(array).toMatchInlineSnapshot(`
|
|
[
|
|
{
|
|
"param": 2,
|
|
},
|
|
{
|
|
"param": 4,
|
|
},
|
|
{
|
|
"param": 6,
|
|
},
|
|
]
|
|
`);
|
|
removeByMutable(array, (item) => item.param !== 4);
|
|
expect(array).toMatchInlineSnapshot(`
|
|
[
|
|
{
|
|
"param": 4,
|
|
},
|
|
]
|
|
`);
|
|
});
|
|
|
|
test("repeatUntil", () => {
|
|
expect(repeatUntil([1, 2, 3], 5)).toEqual([1, 2, 3, 1, 2]);
|
|
expect(repeatUntil([1, 2, 3], 1)).toEqual([1, 2, 3]);
|
|
});
|