mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 10:59:50 +00:00
Add unit tests for common/array files (#23006)
* add vitest coverage * Add js doc to functions * Add tests for common/array
This commit is contained in:
28
test/common/array/ensure-array.test.ts
Normal file
28
test/common/array/ensure-array.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ensureArray } from "../../../src/common/array/ensure-array";
|
||||
|
||||
describe("ensureArray", () => {
|
||||
it("should return undefined when input is undefined", () => {
|
||||
expect(ensureArray(undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return the same array when input is an array", () => {
|
||||
const arr = [1, 2, 3];
|
||||
expect(ensureArray(arr)).toBe(arr);
|
||||
});
|
||||
|
||||
it("should wrap non-array value in an array", () => {
|
||||
const value = 5;
|
||||
expect(ensureArray(value)).toEqual([value]);
|
||||
});
|
||||
|
||||
it("should wrap non-array object in an array", () => {
|
||||
const value = { key: "value" };
|
||||
expect(ensureArray(value)).toEqual([value]);
|
||||
});
|
||||
|
||||
it("should return the same readonly array when input is a readonly array", () => {
|
||||
const arr = [1, 2, 3] as const;
|
||||
expect(ensureArray(arr)).toBe(arr);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user