forked from nativewind/react-native-css
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassName-with-style.test.tsx
More file actions
90 lines (73 loc) · 2.71 KB
/
className-with-style.test.tsx
File metadata and controls
90 lines (73 loc) · 2.71 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { render } from "@testing-library/react-native";
import { Text } from "react-native-css/components/Text";
import { View } from "react-native-css/components/View";
import { registerCSS, testID } from "react-native-css/jest";
test("className with inline style props should coexist when different properties", () => {
registerCSS(`.text-red { color: red; }`);
const component = render(
<Text testID={testID} className="text-red" style={{ fontSize: 16 }} />,
).getByTestId(testID);
// Both className and style props should be applied as array
expect(component.props.style).toEqual([
{ color: "#f00" }, // Changed from "red" to "#f00"
{ fontSize: 16 },
]);
});
test("className with inline style props should favor inline when same property", () => {
registerCSS(`.text-red { color: red; }`);
const component = render(
<Text testID={testID} className="text-red" style={{ color: "blue" }} />,
).getByTestId(testID);
// When same property exists, inline style should win (not array)
expect(component.props.style).toEqual({ color: "blue" });
});
test("only className should not create array", () => {
registerCSS(`.text-red { color: red; }`);
const component = render(
<Text testID={testID} className="text-red" />,
).getByTestId(testID);
// Only className should be a flat object
expect(component.props.style).toEqual({ color: "#f00" }); // Changed from "red" to "#f00"
});
test("only inline style should not create array", () => {
const component = render(
<Text testID={testID} style={{ color: "blue" }} />,
).getByTestId(testID);
// Only inline style should be a flat object
expect(component.props.style).toEqual({ color: "blue" });
});
test("important should overwrite the inline style", () => {
registerCSS(`.text-red\\! { color: red !important; }`);
const component = render(
<Text testID={testID} className="text-red!" style={{ color: "blue" }} />,
).getByTestId(testID);
expect(component.props.style).toEqual({ color: "#f00" });
});
test("View with multiple className properties where inline style takes precedence", () => {
registerCSS(`
.px-4 { padding-left: 16px; padding-right: 16px; }
.pt-4 { padding-top: 16px; }
.mb-4 { margin-bottom: 16px; }
`);
const component = render(
<View
testID={testID}
className="px-4 pt-4 mb-4"
style={{ width: 300, paddingRight: 0 }}
/>,
).getByTestId(testID);
// Inline style should override paddingRight from px-4 class
// Other className styles should be preserved in array
expect(component.props.style).toEqual([
{
paddingLeft: 16,
paddingRight: 16,
paddingTop: 16,
marginBottom: 16,
},
{
width: 300,
paddingRight: 0,
},
]);
});