Passed
Push — main ( 006f41...5dc5e5 )
by Andrii
02:46
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
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
}