Passed
Push — main ( 394b21...fd6a98 )
by Andrii
02:09
created

expect-to-same-render.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 22
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ➔ toStatic 0 3 1
A ➔ expectRender 0 10 1
1
import {renderToStaticMarkup} from "react-dom/server"
2
3
type RElement = Parameters<typeof renderToStaticMarkup>[0]
4
5
export default expectRender
6
7
function expectRender(
8
  ...elements: RElement[]
9
) {
10
  const input = toStatic(elements)
11
12
  return {
13
    toSame: (...expectations: RElement[]) => expect(input).toBe(toStatic(expectations)),
14
    not: {
15
      toSame: (...expectations: RElement[]) => expect(input).not.toBe(toStatic(expectations)),
16
    }
17
  }
18
}
19
20
function toStatic(els: RElement[]) {
21
  return els.map(renderToStaticMarkup).join("")
22
}