|
| 1 | +import { render } from "@testing-library/react-native"; |
| 2 | +import { Text } from "react-native-css/components/Text"; |
| 3 | +import { registerCSS, testID } from "react-native-css/jest"; |
| 4 | + |
| 5 | +test("className with inline style props should coexist when different properties", () => { |
| 6 | + registerCSS(`.text-red { color: red; }`); |
| 7 | + |
| 8 | + const component = render( |
| 9 | + <Text testID={testID} className="text-red" style={{ fontSize: 16 }} />, |
| 10 | + ).getByTestId(testID); |
| 11 | + |
| 12 | + // Both className and style props should be applied as array |
| 13 | + expect(component.props.style).toEqual([ |
| 14 | + { color: "#f00" }, // Changed from "red" to "#f00" |
| 15 | + { fontSize: 16 }, |
| 16 | + ]); |
| 17 | +}); |
| 18 | + |
| 19 | +test("className with inline style props should favor inline when same property", () => { |
| 20 | + registerCSS(`.text-red { color: red; }`); |
| 21 | + |
| 22 | + const component = render( |
| 23 | + <Text testID={testID} className="text-red" style={{ color: "blue" }} />, |
| 24 | + ).getByTestId(testID); |
| 25 | + |
| 26 | + // When same property exists, inline style should win (not array) |
| 27 | + expect(component.props.style).toEqual({ color: "blue" }); |
| 28 | +}); |
| 29 | + |
| 30 | +test("only className should not create array", () => { |
| 31 | + registerCSS(`.text-red { color: red; }`); |
| 32 | + |
| 33 | + const component = render( |
| 34 | + <Text testID={testID} className="text-red" />, |
| 35 | + ).getByTestId(testID); |
| 36 | + |
| 37 | + // Only className should be a flat object |
| 38 | + expect(component.props.style).toEqual({ color: "#f00" }); // Changed from "red" to "#f00" |
| 39 | +}); |
| 40 | + |
| 41 | +test("only inline style should not create array", () => { |
| 42 | + const component = render( |
| 43 | + <Text testID={testID} style={{ color: "blue" }} />, |
| 44 | + ).getByTestId(testID); |
| 45 | + |
| 46 | + // Only inline style should be a flat object |
| 47 | + expect(component.props.style).toEqual({ color: "blue" }); |
| 48 | +}); |
0 commit comments