src/bem.core.test.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 65
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 52
mnd 1
bc 1
fnc 0
dl 0
loc 65
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import type {BemInGeneral} from "./bem.types"
2
import {
3
  bem2arr,
4
  setOptions
5
} from "./bem.core";
6
7
describe(bem2arr.name, () => {
8
  describe("singletons", () => {
9
    const suites: Record<string, [BemInGeneral, string][]> = {
10
      "singletons": [
11
        [{base: undefined  },  "base"],
12
        [{base: false      },  "base"],
13
        [{base: true       },  "base"],
14
        [{base: "mod"      },  "base base--mod"],
15
        [{base: ["mod"]    },  "base base--mod"],
16
        [{base: [false]    },  "base"],
17
        [{base: {}         },  "base"],
18
        [{base: {mod: false}}, "base"],
19
        [{base: {mod: true }}, "base base--mod"],
20
        [{base: {mod: "val"}}, "base base--mod--val"],
21
        [{base: [{mod: false}]}, "base"],
22
        [{base: [{mod: true }]}, "base base--mod"],
23
        [{base: [{mod: "val"}]}, "base base--mod--val"],
24
      ],
25
    }
26
27
    Object.entries(suites).forEach(([title, launches]) => describe(title, () => launches
28
      .forEach(([query, output]) => it(
29
        JSON.stringify(query, (_, v) => v === undefined ? "`undefined`" : v),
30
        () => expect(bem2arr(query).join(" ")).toBe(output))
31
      )
32
    ))
33
  })
34
})
35
36
describe("optioning", () => {
37
  afterAll(() => setOptions({
38
    elementDelimiter: "__",
39
    modDelimiter: "--",
40
  }))
41
42
  it("another mod", () => {
43
    setOptions({modDelimiter: "-"})
44
    expect(bem2arr({
45
      base: {mod: "val"}
46
    }).join(" ")).toBe(
47
      "base base-mod-val"
48
    )
49
  })
50
51
  it("another el", () => {
52
    //#Useful in #30
53
    setOptions({elementDelimiter: "_"})
54
    expect(true).toBe(true)
55
  })
56
})
57
58
it("extended values shape", () => expect(bem2arr({
59
  base: [
60
    {"mod1": 1},
61
    "mod2"
62
  ]
63
}).join(" ")).toBe(
64
  "base base--mod1--1 base--mod2"
65
))