-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbem.core.test.ts
65 lines (59 loc) · 1.68 KB
/
bem.core.test.ts
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
import type {BemInGeneral} from "./bem.types"
import {
bem2arr,
setOptions
} from "./bem.core";
describe(bem2arr.name, () => {
describe("singletons", () => {
const suites: Record<string, [BemInGeneral, string][]> = {
"singletons": [
[{base: undefined }, "base"],
[{base: false }, "base"],
[{base: true }, "base"],
[{base: "mod" }, "base base--mod"],
[{base: ["mod"] }, "base base--mod"],
[{base: [false] }, "base"],
[{base: {} }, "base"],
[{base: {mod: false}}, "base"],
[{base: {mod: true }}, "base base--mod"],
[{base: {mod: "val"}}, "base base--mod--val"],
[{base: [{mod: false}]}, "base"],
[{base: [{mod: true }]}, "base base--mod"],
[{base: [{mod: "val"}]}, "base base--mod--val"],
],
}
Object.entries(suites).forEach(([title, launches]) => describe(title, () => launches
.forEach(([query, output]) => it(
JSON.stringify(query, (_, v) => v === undefined ? "`undefined`" : v),
() => expect(bem2arr(query).join(" ")).toBe(output))
)
))
})
})
describe("optioning", () => {
afterAll(() => setOptions({
elementDelimiter: "__",
modDelimiter: "--",
}))
it("another mod", () => {
setOptions({modDelimiter: "-"})
expect(bem2arr({
base: {mod: "val"}
}).join(" ")).toBe(
"base base-mod-val"
)
})
it("another el", () => {
//#Useful in #30
setOptions({elementDelimiter: "_"})
expect(true).toBe(true)
})
})
it("extended values shape", () => expect(bem2arr({
base: [
{"mod1": 1},
"mod2"
]
}).join(" ")).toBe(
"base base--mod1--1 base--mod2"
))