test: web tests

This commit is contained in:
Mark Lawlor
2022-10-26 17:46:40 +10:00
parent 83d7c34bd1
commit cb084dd242
3 changed files with 71 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
import { render } from "@testing-library/react-native";
import { FunctionComponent } from "react";
import { ViewProps } from "react-native";
import { styled } from "../../src";
const Component = jest.fn(
(props) => props.children
) as FunctionComponent<ViewProps>;
afterEach(() => {
jest.clearAllMocks();
});
test("styled", () => {
const StyledComponent = styled(Component);
render(<StyledComponent className="text-black" />);
expect(Component).toHaveBeenCalledWith(
{
style: {
$$css: true,
tailwind: "text-black",
},
},
{}
);
});
test("default styles", () => {
const StyledComponent = styled(Component, "bg-white");
render(<StyledComponent className="text-black" />);
expect(Component).toHaveBeenCalledWith(
{
style: {
$$css: true,
tailwind: "bg-white text-black",
},
},
{}
);
});
test("cva options", () => {
const StyledComponent = styled(Component, "bg-white", {
variants: {
size: {
large: "p-4",
},
},
});
render(<StyledComponent className="text-black" size="large" />);
expect(Component).toHaveBeenCalledWith(
{
size: "large",
style: {
$$css: true,
tailwind: "bg-white p-4 text-black",
},
},
{}
);
});

View File

@@ -23,7 +23,10 @@ export function styled(
? styledBaseClassNameOrOptions
: baseClassName;
const classGenerator = cva(`${classProps} ${defaultClassName} `, cvaOptions);
const classGenerator = cva(
[classProps, defaultClassName].filter(Boolean).join(" "),
cvaOptions
);
const Styled = forwardRef<unknown, any>(function (
{ className, tw, ...props },