Skip to content

Commit 0a015eb

Browse files
committed
fix: fix broken tests
1 parent 254bf73 commit 0a015eb

File tree

1 file changed

+36
-73
lines changed

1 file changed

+36
-73
lines changed

src/index.test.tsx

Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,14 @@ import { createDash, createStyles, styles } from "@dash-ui/styles";
44
import { render as renderComponent } from "@testing-library/react";
55
import { cleanup, renderHook } from "@testing-library/react-hooks";
66
import * as React from "react";
7-
import {
8-
DashProvider,
9-
Inline,
10-
useDash,
11-
useGlobal,
12-
useThemes,
13-
useTokens,
14-
} from "./index";
7+
import { Inline, useGlobal, useThemes, useTokens } from "./index";
158

169
afterEach(() => {
1710
document.getElementsByTagName("html")[0].innerHTML = "";
1811
});
1912

20-
const opt = (props = {}) => ({
21-
wrapper: (other) => <DashProvider {...props} {...other} />,
22-
});
23-
24-
const renderFragment = (children = null, props = {}, options = {}) =>
13+
const renderFragment = (children = null, options = {}) =>
2514
renderComponent(children, {
26-
wrapper: ({ children }) => <DashProvider {...props} children={children} />,
2715
...options,
2816
}).asFragment();
2917

@@ -41,38 +29,18 @@ declare module "@dash-ui/styles" {
4129
}
4230
}
4331

44-
describe("<DashProvider>", () => {
45-
afterEach(cleanup);
46-
47-
it("provides the default styles() configuration", () => {
48-
const { result } = renderHook(() => useDash(), opt());
49-
expect(result.current.styles).toBe(styles);
50-
});
51-
52-
it("provides a custom styles() configuration", () => {
53-
const myStyles = createStyles();
54-
const { result } = renderHook(() => useDash(), opt({ styles: myStyles }));
55-
expect(result.current.styles).toBe(myStyles);
56-
});
57-
58-
it("works without a provider", () => {
59-
const { result } = renderHook(() => useDash());
60-
expect(result.current.styles).toBe(styles);
61-
});
62-
});
63-
6432
describe("<Inline>", () => {
6533
afterEach(cleanup);
6634

6735
it("writes css", () => {
6836
expect(
6937
renderFragment(
7038
<Inline
39+
styles={styles}
7140
css={`
7241
display: block;
7342
`}
74-
/>,
75-
{ styles }
43+
/>
7644
)
7745
).toMatchSnapshot();
7846
});
@@ -84,18 +52,18 @@ describe("<Inline>", () => {
8452
expect(
8553
renderFragment(
8654
<Inline
55+
styles={myStyles}
8756
css={`
8857
display: block;
8958
`}
90-
/>,
91-
{ styles: myStyles }
59+
/>
9260
)
9361
).toMatchSnapshot();
9462
});
9563

9664
it("writes css object", () => {
9765
expect(
98-
renderFragment(<Inline css={{ display: "block" }} />, { styles })
66+
renderFragment(<Inline styles={styles} css={{ display: "block" }} />)
9967
).toMatchSnapshot();
10068
});
10169

@@ -104,10 +72,10 @@ describe("<Inline>", () => {
10472

10573
expect(
10674
renderFragment(
107-
<Inline css={({ color }) => `color: ${color.primary};`} />,
108-
{
109-
styles: myStyles,
110-
}
75+
<Inline
76+
styles={myStyles}
77+
css={({ color }) => `color: ${color.primary};`}
78+
/>
11179
)
11280
).toMatchSnapshot();
11381
});
@@ -117,19 +85,16 @@ describe("<Inline>", () => {
11785
myStyles.insertTokens({ color: { primary: "#000" } });
11886

11987
expect(
120-
renderFragment(<Inline css={""} />, {
121-
styles: myStyles,
122-
})
88+
renderFragment(<Inline styles={myStyles} css={""} />)
12389
).toMatchSnapshot();
12490
});
12591
});
12692

12793
describe("useGlobal()", () => {
12894
it("sets global styles with a string value", async () => {
12995
const myStyles = createStyles();
130-
const { unmount, rerender } = renderHook(
131-
() => useGlobal(`:root { --blue: #09a; }`),
132-
opt({ styles: myStyles })
96+
const { unmount, rerender } = renderHook(() =>
97+
useGlobal(myStyles, `:root { --blue: #09a; }`)
13398
);
13499

135100
rerender();
@@ -145,9 +110,11 @@ describe("useGlobal()", () => {
145110
it("sets global styles with a function value", async () => {
146111
const myStyles = createStyles();
147112
myStyles.insertTokens({ color: { primary: "#000", secondary: "#fff" } });
148-
const { unmount, rerender } = renderHook(
149-
() => useGlobal(({ color }) => `body { background: ${color.primary}; }`),
150-
opt({ styles: myStyles })
113+
const { unmount, rerender } = renderHook(() =>
114+
useGlobal(
115+
myStyles,
116+
({ color }) => `body { background: ${color.primary}; }`
117+
)
151118
);
152119

153120
rerender();
@@ -165,16 +132,16 @@ describe("useGlobal()", () => {
165132

166133
it("handles falsy values", async () => {
167134
const myStyles = createStyles();
168-
renderHook(() => useGlobal(false), opt({ styles: myStyles }));
135+
renderHook(() => useGlobal(myStyles, false));
169136
expect(document.querySelectorAll(`style[data-dash]`).length).toBe(0);
170137

171-
renderHook(() => useGlobal(0), opt({ styles: myStyles }));
138+
renderHook(() => useGlobal(myStyles, 0));
172139
expect(document.querySelectorAll(`style[data-dash]`).length).toBe(0);
173140

174-
renderHook(() => useGlobal(null), opt({ styles: myStyles }));
141+
renderHook(() => useGlobal(myStyles, null));
175142
expect(document.querySelectorAll(`style[data-dash]`).length).toBe(0);
176143

177-
renderHook(() => useGlobal(""), opt({ styles: myStyles }));
144+
renderHook(() => useGlobal(myStyles, ""));
178145
expect(document.querySelectorAll(`style[data-dash]`).length).toBe(0);
179146
await cleanup();
180147
});
@@ -185,12 +152,10 @@ describe("useTokens()", () => {
185152

186153
it("adds tokens then cleans up", async () => {
187154
const myStyles = createStyles();
188-
const { unmount, rerender } = renderHook(
189-
() =>
190-
useTokens({
191-
color: { primary: "#000", secondary: "#fff" },
192-
}),
193-
opt({ styles: myStyles })
155+
const { unmount, rerender } = renderHook(() =>
156+
useTokens(myStyles, {
157+
color: { primary: "#000", secondary: "#fff" },
158+
})
194159
);
195160

196161
rerender();
@@ -208,17 +173,15 @@ describe("useThemes()", () => {
208173
afterEach(cleanup);
209174

210175
it("adds tokens then cleans up", async () => {
211-
const { unmount, rerender } = renderHook(
212-
() =>
213-
useThemes({
214-
dark: {
215-
color: { primary: "#000", secondary: "#fff" },
216-
},
217-
light: {
218-
color: { primary: "#fff", secondary: "#000" },
219-
},
220-
}),
221-
opt({ styles: createStyles() })
176+
const { unmount, rerender } = renderHook(() =>
177+
useThemes(createStyles(), {
178+
dark: {
179+
color: { primary: "#000", secondary: "#fff" },
180+
},
181+
light: {
182+
color: { primary: "#fff", secondary: "#000" },
183+
},
184+
})
222185
);
223186

224187
rerender();

0 commit comments

Comments
 (0)