Passed
Push — main ( ea1a67...5c568c )
by Andrii
02:15
created

direct.test.ts ➔ direct   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
cc 1
1
import { dehash, joinWithLead } from "./core";
2
import { ClassValue } from "./defs";
3
import {stringifyClassNamed} from "./utils"
4
5
describe(direct.name, () => {
6
  const output = direct({class1: undefined, class2: "hash2"})
7
  , className = "class1 hash2"
8
9
  it("has classNames", () => expect(
10
    {...output}
11
  ).toStrictEqual(
12
    {className}
13
  ))
14
  it("stringable", () => expect(
15
    `${output}`
16
  ).toBe(
17
    className
18
  ))
19
  it("called", () => expect({
20
    ...output({
21
      class3: undefined, class4: "hash4"
22
    })
23
  }).toStrictEqual({
24
    "className": `${className} class3 hash4`
25
  }))
26
  it("called is strigable", () => expect(
27
    `${output({
28
      class3: undefined, class4: "hash4"
29
    })}`
30
  ).toBe(
31
    `${className} class3 hash4`
32
  ))
33
})
34
35
function direct<T extends Record<string, ClassValue>>(classes: T, propagate?: string) {
36
  const className = joinWithLead(propagate, dehash(classes))  
37
  , host = (classes: Record<string, ClassValue>) => direct(classes, className)
38
39
  host["className"] = className
40
  stringifyClassNamed(host)
41
42
  return host
43
}