-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcomponents.test.tsx
More file actions
56 lines (46 loc) · 1.67 KB
/
components.test.tsx
File metadata and controls
56 lines (46 loc) · 1.67 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
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" });
});