Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Checked type errors #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 14 additions & 17 deletions packages/core/src/createStyleBuilder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PropsWithChildren } from "react";
import { renderHook } from "@testing-library/react-hooks";

let colorScheme = "light";
const MockText = vi.fn();
const MockText = vi.fn(() => 0);

vi.mock("react-native", () => ({
StyleSheet: {
Expand All @@ -25,7 +25,7 @@ describe("createStyleBuilder", () => {
it("creates builder with default constraints/handlers", () => {
const { styles } = createStyleBuilder();
expect(styles("p:1")).toEqual({ padding: C["1"] });
// @ts-expect-error
// @ts-expect-error // Testing incorrect type
expect(styles("nope?")).toEqual({});
});

Expand All @@ -43,14 +43,13 @@ describe("createStyleBuilder", () => {
it("allows overriding theme values", () => {
const { styles } = createStyleBuilder({
overrideTheme: {
spacing: { sm: 4, md: 8 },
spacing: { sm: 4, md: 8, 0: 0 },
},
});

expect(styles("p:sm")).toEqual({ padding: 4 });
expect(styles("p:md")).toEqual({ padding: 8 });
// @ts-expect-error
expect(styles("p:0")).toEqual({});
expect(styles("p:0")).toEqual({ padding: 0 });
});

it("allows extending theme values", () => {
Expand Down Expand Up @@ -150,11 +149,10 @@ describe("createStyleBuilder().makeStyledComponent", () => {
const StyledText = makeStyledComponent(Text);
render(<StyledText classes={["bg:red-100"]}>Hello world</StyledText>);

// @ts-expect-error HALP. How do I type this mock?
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
backgroundColor: DefaultTheme.colors["red-100"],
});
// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].children).toEqual("Hello world");
});

Expand All @@ -169,11 +167,11 @@ describe("createStyleBuilder().makeStyledComponent", () => {
{ wrapper: Wrapper }
);

// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
backgroundColor: DefaultTheme.colors["blue-100"],
});
// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].children).toEqual("Hello world");
});
});
Expand All @@ -188,7 +186,7 @@ describe("createStyleBuilder().styled", () => {
const MyText = styled(Text)("color:red-100");
render(<MyText>Hey world</MyText>);

// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
color: DefaultTheme.colors["red-100"],
});
Expand All @@ -199,8 +197,7 @@ describe("createStyleBuilder().styled", () => {
classes: ["color:red-200"],
});
render(<MyText>Hey world</MyText>);

// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
color: DefaultTheme.colors["red-200"],
});
Expand All @@ -213,14 +210,14 @@ describe("createStyleBuilder().styled", () => {
});

render(<MyText>Hey world</MyText>, { wrapper: Wrapper });
// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
color: DefaultTheme.colors["red-100"],
});

colorScheme = "dark";
render(<MyText>Hey world</MyText>, { wrapper: Wrapper });
// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
color: DefaultTheme.colors["blue-100"],
});
Expand All @@ -234,20 +231,20 @@ describe("createStyleBuilder().styled", () => {

// no isItalic prop
render(<MyText>Hello world</MyText>, { wrapper: Wrapper });
// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({});

// with isItalic prop
render(<MyText isItalic>Hello world</MyText>, { wrapper: Wrapper });
// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
fontStyle: "italic",
});

// Dark mode
colorScheme = "dark";
render(<MyText isItalic>Hello world</MyText>, { wrapper: Wrapper });
// @ts-expect-error HALP. How do I type this mock?
// @ts-expect-error //Vitest missing types
expect(MockText.calls?.at(-1)?.[0].style[0]).toEqual({
fontStyle: "italic",
color: DefaultTheme.colors["red-100"],
Expand Down