Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/__tests__/native/components.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Button as RNButton, type ButtonProps } from "react-native";

import { render } from "@testing-library/react-native";
import { copyComponentProperties } from "react-native-css/components/copyComponentProperties";
import { registerCSS, testID } from "react-native-css/jest";
import { useCssElement } from "react-native-css/native";
import type {
StyledConfiguration,
StyledProps,
} from "react-native-css/runtime.types";

test("Component preserves props when mapping specifies 'target: false'", () => {
registerCSS(`.sign-in { color: orange; }`);

const mapping: StyledConfiguration<typeof RNButton> = {
className: {
target: false,
nativeStyleMapping: {
color: "color",
},
},
};

const Button = copyComponentProperties(
RNButton,
(props: StyledProps<ButtonProps, typeof mapping>) => {
return useCssElement(RNButton, props, mapping);
},
);

const onPress = jest.fn();

const result = render(
<Button
testID={testID}
className="sign-in"
title="Sign In"
onPress={onPress}
/>,
);

expect(result.getByText("Sign In")).toBeTruthy();

const renderedElement = result.getByTestId(testID);
const renderedProps = renderedElement.props;

expect(renderedProps.testID).toBe(testID);
expect(renderedProps).not.toHaveProperty("className");

// the <Text> element in the RN button
// should apply an orange color to the element (because of the "sign-in" className)
const titleElement = result.getByText("Sign In");
expect(titleElement.props.style).toBeInstanceOf(Array);
expect(titleElement.props.style).toHaveLength(2);
expect(titleElement.props.style[1]).toEqual({ color: "#ffa500" });
});
2 changes: 1 addition & 1 deletion src/native/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function deepMergeConfig(
result = Object.assign({}, left, right);
}
} else {
result = { ...left };
result = Object.assign({}, left, right);
}

if (
Expand Down