-
Notifications
You must be signed in to change notification settings - Fork 1
/
useTheme.test.mjs
69 lines (60 loc) · 1.68 KB
/
useTheme.test.mjs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint-disable react-hooks/rules-of-hooks */
import assert from "node:assert/strict";
import useTheme from "./useTheme.mjs";
import { createElement } from "react";
import ReactHookTest from "./test-utils/ReactHookTest.mjs";
import theme from "./test-utils/theme.mjs";
import MysticalProvider from "./MysticalProvider.mjs";
import test from "node:test";
import { render } from "@testing-library/react";
import "global-jsdom/register";
test("useTheme", async (t) => {
await t.test("reads values", () => {
const hookResults = [];
render(
createElement(
MysticalProvider,
{ theme },
createElement(ReactHookTest, {
hook() {
return useTheme("colors", "emerald.500");
},
results: hookResults,
}),
),
);
assert.equal(hookResults[0], theme.colors.emerald["500"]);
});
await t.test("retains values that aren't found", () => {
const hookResults = [];
render(
createElement(
MysticalProvider,
{ theme },
createElement(ReactHookTest, {
hook() {
return useTheme("colors", "emerald.1000");
},
results: hookResults,
}),
),
);
assert.equal(hookResults[0], "emerald.1000");
});
await t.test("self referencing values are transformed", () => {
const hookResults = [];
render(
createElement(
MysticalProvider,
{ theme },
createElement(ReactHookTest, {
hook() {
return useTheme("colors", "brand.primary");
},
results: hookResults,
}),
),
);
assert.equal(hookResults[0], theme.colors.emerald["500"]);
});
});