-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelpers.ts
More file actions
46 lines (38 loc) · 1.21 KB
/
helpers.ts
File metadata and controls
46 lines (38 loc) · 1.21 KB
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
import { StyleSheet } from "react-native";
import { ReactTestInstance } from "react-test-renderer";
import { AssertiveStyle, StyleObject } from "./types";
/**
* Checks if a value is empty.
*
* @param value - The value to check.
* @returns `true` if the value is empty, `false` otherwise.
*/
export function isEmpty(value: unknown): boolean {
if (!value) {
return true;
}
if (Array.isArray(value)) {
return value.length === 0;
}
return false;
}
/**
* Converts a ReactTestInstance to a string representation.
*
* @param instance - The ReactTestInstance to convert.
* @returns A string representation of the instance.
*/
export function instanceToString(instance: ReactTestInstance | null): string {
if (instance === null) {
return "null";
}
return `<${instance.type.toString()} ... />`;
}
export function getFlattenedStyle(style: AssertiveStyle): StyleObject {
const flattenedStyle = StyleSheet.flatten(style);
return flattenedStyle ? (flattenedStyle as StyleObject) : {};
}
export function styleToString(flattenedStyle: StyleObject): string {
const styleEntries = Object.entries(flattenedStyle);
return styleEntries.map(([key, value]) => `\t- ${key}: ${String(value)};`).join("\n");
}