__tests__/toggling.spec.tsx   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 52
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 40
mnd 0
bc 0
fnc 2
dl 0
loc 52
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A toggling.spec.tsx ➔ Component 0 7 1
A toggling.spec.tsx ➔ App 0 15 1
1
import React from "react"
2
import type { ClassNames, ClassNamesProperty, ClassHash } from "../src"
3
import classNaming, { classNamesCheck } from "../src"
4
import expectRender from "../expect-to-same-render"
5
6
const {classnames}: ClassNames<typeof App> = {
7
  classnames: {
8
    "App__Item": "hash",
9
    class1: "hash1",
10
    class2: "hash2"
11
  }
12
}
13
14
function App({classnames, className}: ClassNames<
15
  true,
16
  ClassNamesProperty<{App__Item: ClassHash}>,
17
  typeof Component
18
>) {
19
  const classes = classNaming({
20
    classnames, className
21
  })
22
23
  return <Component {...{
24
    ...classes(
25
      true, {App__Item: true}
26
    ),
27
    classnames
28
  }}/>
29
}
30
31
function Component(props: ClassNames<true, ClassNamesProperty<{class1: ClassHash, class2: ClassHash}>>) {
32
  const classes = classNaming(props)
33
  return <>
34
    <div {...classes(true, {class1: true, class2: false})}/>
35
    <div {...classes({class2: true})}/>
36
  </>
37
}
38
39
it("not module", () => expectRender(
40
  <App className="MyApp" classnames={classNamesCheck()} />
41
).toSame(
42
  <div className="MyApp App__Item class1" />,
43
  <div className="class2" />
44
))
45
46
it("css module", () => expectRender(
47
  <App className="MyApp" classnames={classnames} />
48
).toSame(
49
  <div className="MyApp hash hash1" />,
50
  <div className="hash2" />
51
))
52