• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KablamoOSS / kerosene / 10839628454

12 Sep 2024 10:23PM CUT coverage: 79.926%. Remained the same
10839628454

push

github

web-flow
build(deps): bump path-to-regexp from 6.2.1 to 6.3.0 (#148)

224 of 282 branches covered (79.43%)

868 of 1086 relevant lines covered (79.93%)

6.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/kerosene-test/src/react/createStubComponent.tsx
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2

3
import { identity } from "lodash";
×
4
import * as React from "react";
×
5

6
export default function createStubComponent<
7
  Props extends Record<string, unknown> = Record<string, unknown>,
8
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
  RenderProps extends readonly any[] = any[],
10
>(displayName: string, functional?: false): React.ComponentClass<Props>;
11

12
export default function createStubComponent<
13
  Props extends Record<string, unknown> = Record<string, unknown>,
14
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
  RenderProps extends readonly any[] = any[],
16
>(displayName: string, functional: true): React.FunctionComponent<Props>;
17

18
export default function createStubComponent<
19
  Props extends Record<string, unknown> = Record<string, unknown>,
20
  RenderProps extends readonly any[] = any[],
21
>(
22
  displayName: string,
23
  functional: false | undefined,
24
  getRenderProps: (props: Omit<Props, "children">) => RenderProps,
25
  transformRenderPropResult?: (
26
    result: (props: any) => React.ReactNode,
27
  ) => React.ReactNode,
28
): React.ComponentClass<
29
  Props & { children: (...args: RenderProps) => React.ReactNode }
30
>;
31

32
export default function createStubComponent<
33
  Props extends Record<string, unknown> = Record<string, unknown>,
34
  RenderProps extends readonly any[] = any[],
35
>(
36
  displayName: string,
37
  functional: true,
38
  getRenderProps: (props: Omit<Props, "children">) => RenderProps,
39
  transformRenderPropResult?: (
40
    result: (props: any) => React.ReactNode,
41
  ) => React.ReactNode,
42
): React.FunctionComponent<
43
  Props & { children: (...args: RenderProps) => React.ReactNode }
44
>;
45

46
/**
47
 * Creates a StubComponent for unit testing
48
 * @param displayName Component displayName which can be used to `EnzymeWrapper#find` the component
49
 * @param functional Whether or not use functional component instead of a class component (defaults to `false`)
50
 * @param getRenderProps Function that returns props that will be passed the the children function
51
 * @param transformRenderPropResult Function to transform the result returned by the render prop (if, for example,
52
 * the returned result is a function itself)
53
 */
54
export default function createStubComponent<
×
55
  Props extends { children?: unknown } = { [prop: string]: unknown },
56
  RenderProps extends readonly any[] = any[],
57
>(
58
  displayName: string,
59
  functional = false,
×
60
  getRenderProps: (props: Omit<Props, "children">) => RenderProps = identity,
×
61
  transformRenderPropResult: (
×
62
    result: (props: any) => React.ReactNode,
63
  ) => React.ReactNode = identity,
64
): React.ComponentType<Props> {
65
  if (functional) {
×
66
    return Object.assign(
×
67
      ({ children, ...props }: Props) => (
68
        // eslint-disable-next-line react/no-unknown-property
69
        <div __displayName__={displayName} {...props}>
×
70
          {typeof children === "function"
×
71
            ? transformRenderPropResult(children(...getRenderProps(props)))
72
            : (children as React.ReactNode)}
73
        </div>
74
      ),
75
      { displayName },
76
    );
77
  }
78

79
  // eslint-disable-next-line react/prefer-stateless-function
80
  return class extends React.Component<Props> {
×
81
    public static displayName = displayName;
×
82

83
    public override render() {
84
      const { children, ...props } = this.props;
×
85

86
      return (
×
87
        // eslint-disable-next-line react/no-unknown-property
88
        <div __displayName__={displayName} {...props}>
89
          {typeof children === "function"
×
90
            ? transformRenderPropResult(
91
                (children as (...args: RenderProps) => React.ReactNode)(
92
                  ...getRenderProps(props),
93
                ) as any,
94
              )
95
            : (children as React.ReactNode)}
96
        </div>
97
      );
98
    }
99
  };
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc