__tests__/index.miss-use.spec.tsx   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 59
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A index.miss-use.spec.tsx ➔ App 0 13 1
A index.miss-use.spec.tsx ➔ Component 0 7 1
1
import React from "react"
2
import type { ClassNames, ClassNamesProperty, ClassHash } from "../src/"
3
import classNaming 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
  return <Component {...{
20
    ...classNaming({
21
      classnames, className
22
    })(
23
      true, {App__Item: true}
24
    ),
25
    classnames
26
  }}/>
27
}
28
29
function Component(props: ClassNames<true, ClassNamesProperty<{class1: ClassHash, class2: ClassHash}>>) {
30
  const classes = classNaming(props)
31
  return <>
32
    <div {...classes(true, {class1: true, class2: false})}/>
33
    <div {...classes({class2: true})}/>
34
  </>
35
}
36
37
it("not propagate classnames", () => {
38
  const App = ({classnames, className}: ClassNames<
39
    true,
40
    ClassNamesProperty<{App__Item: ClassHash}>,
41
    typeof Component>
42
  ) =>
43
    //@ts-expect-error Types of property classnames are incompatible Type undefined is not assignable
44
    <Component {
45
      ...classNaming({
46
        classnames, className
47
      })(
48
        true, {App__Item: true}
49
      )}
50
    />
51
52
  expectRender(
53
    <App className="MyApp" classnames={classnames}/>
54
  ).toSame(
55
    <div className="MyApp hash class1" />,
56
    <div className="class2" />
57
  )
58
})
59