diff --git a/packages/nativewind/__tests__/web/index.tsx b/packages/nativewind/__tests__/web/styled-component.tsx similarity index 100% rename from packages/nativewind/__tests__/web/index.tsx rename to packages/nativewind/__tests__/web/styled-component.tsx diff --git a/packages/nativewind/__tests__/web/styled.tsx b/packages/nativewind/__tests__/web/styled.tsx new file mode 100644 index 0000000..a37585f --- /dev/null +++ b/packages/nativewind/__tests__/web/styled.tsx @@ -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; + +afterEach(() => { + jest.clearAllMocks(); +}); + +test("styled", () => { + const StyledComponent = styled(Component); + + render(); + + expect(Component).toHaveBeenCalledWith( + { + style: { + $$css: true, + tailwind: "text-black", + }, + }, + {} + ); +}); + +test("default styles", () => { + const StyledComponent = styled(Component, "bg-white"); + + render(); + + 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(); + + expect(Component).toHaveBeenCalledWith( + { + size: "large", + style: { + $$css: true, + tailwind: "bg-white p-4 text-black", + }, + }, + {} + ); +}); diff --git a/packages/nativewind/src/styled/web/index.tsx b/packages/nativewind/src/styled/web/index.tsx index cdb8eaa..467379d 100644 --- a/packages/nativewind/src/styled/web/index.tsx +++ b/packages/nativewind/src/styled/web/index.tsx @@ -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(function ( { className, tw, ...props },