File size: 1,098 Bytes
cf86710 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import { getDataAttributes } from "./getDataAttributes";
// Mocking the types that are defined elsewhere.
// TODO: does it work? Replace the types with the actual types.
interface PropsBase {
[key: string]: unknown;
}
test("return all data- attributes from the props", () => {
const props: PropsBase = {
"data-test-id": "123",
"data-role": "button",
"aria-label": "test element",
};
const result = getDataAttributes(props);
expect(result).toEqual({
"data-test-id": "123",
"data-role": "button",
});
});
test("return an empty object if there are no data- attributes", () => {
const props: PropsBase = {
"aria-label": "test element",
class: "example-class",
};
const result = getDataAttributes(props);
expect(result).toEqual({});
});
test("handle props with undefined or null values", () => {
const props: PropsBase = {
"data-test-id": undefined,
"data-role": null,
"aria-hidden": "true",
};
const result = getDataAttributes(props);
expect(result).toEqual({
"data-test-id": undefined,
"data-role": null,
});
});
|