|
1 | 1 | import { render } from "@testing-library/react-native"; |
2 | 2 | import { Text } from "react-native-css/components/Text"; |
| 3 | +import { View } from "react-native-css/components/View"; |
3 | 4 | import { registerCSS, testID } from "react-native-css/jest"; |
4 | 5 |
|
5 | 6 | test("className with inline style props should coexist when different properties", () => { |
@@ -46,3 +47,44 @@ test("only inline style should not create array", () => { |
46 | 47 | // Only inline style should be a flat object |
47 | 48 | expect(component.props.style).toEqual({ color: "blue" }); |
48 | 49 | }); |
| 50 | + |
| 51 | +test("important should overwrite the inline style", () => { |
| 52 | + registerCSS(`.text-red\\! { color: red !important; }`); |
| 53 | + |
| 54 | + const component = render( |
| 55 | + <Text testID={testID} className="text-red!" style={{ color: "blue" }} />, |
| 56 | + ).getByTestId(testID); |
| 57 | + |
| 58 | + expect(component.props.style).toEqual({ color: "#f00" }); |
| 59 | +}); |
| 60 | + |
| 61 | +test("View with multiple className properties where inline style takes precedence", () => { |
| 62 | + registerCSS(` |
| 63 | + .px-4 { padding-left: 16px; padding-right: 16px; } |
| 64 | + .pt-4 { padding-top: 16px; } |
| 65 | + .mb-4 { margin-bottom: 16px; } |
| 66 | + `); |
| 67 | + |
| 68 | + const component = render( |
| 69 | + <View |
| 70 | + testID={testID} |
| 71 | + className="px-4 pt-4 mb-4" |
| 72 | + style={{ width: 300, paddingRight: 0 }} |
| 73 | + />, |
| 74 | + ).getByTestId(testID); |
| 75 | + |
| 76 | + // Inline style should override paddingRight from px-4 class |
| 77 | + // Other className styles should be preserved in array |
| 78 | + expect(component.props.style).toEqual([ |
| 79 | + { |
| 80 | + paddingLeft: 16, |
| 81 | + paddingRight: 16, |
| 82 | + paddingTop: 16, |
| 83 | + marginBottom: 16, |
| 84 | + }, |
| 85 | + { |
| 86 | + width: 300, |
| 87 | + paddingRight: 0, |
| 88 | + }, |
| 89 | + ]); |
| 90 | +}); |
0 commit comments