@quilted/react-testing
Advanced tools
Comparing version 0.3.6 to 0.3.7
@@ -10,17 +10,32 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
const defaultRender = element => element; | ||
const TestRenderer = /*#__PURE__*/(0, _react.forwardRef)(({ | ||
children, | ||
render = defaultRender | ||
}, ref) => { | ||
const [props, setProps] = (0, _react.useState)(); | ||
(0, _react.useImperativeHandle)(ref, () => ({ | ||
setProps(newProps) { | ||
setProps(newProps); | ||
} | ||
class TestRenderer extends _react.Component { | ||
constructor(...args) { | ||
super(...args); | ||
})); | ||
return render(props ? /*#__PURE__*/(0, _react.cloneElement)(children, props) : children); | ||
}); | ||
_defineProperty(this, "state", {}); | ||
} | ||
setProps(props) { | ||
this.setState({ | ||
props | ||
}); | ||
} | ||
render() { | ||
const { | ||
props | ||
} = this.state; | ||
const { | ||
children, | ||
render = defaultRender | ||
} = this.props; | ||
return render(props ? /*#__PURE__*/(0, _react.cloneElement)(children, props) : children); | ||
} | ||
} | ||
exports.TestRenderer = TestRenderer; |
@@ -1,13 +0,16 @@ | ||
import type { ReactNode, Ref, ReactElement } from 'react'; | ||
interface Props<ComponentProps = unknown> { | ||
import { Component } from 'react'; | ||
import type { ReactElement, ReactNode } from 'react'; | ||
interface State<ComponentProps> { | ||
props?: Partial<ComponentProps>; | ||
} | ||
interface Props<ComponentProps> { | ||
children?: ReactNode; | ||
render?(element: ReactElement<ComponentProps>): ReactElement<ComponentProps>; | ||
} | ||
export interface ImperativeApi<ComponentProps = unknown> { | ||
export declare class TestRenderer<ComponentProps> extends Component<Props<ComponentProps>, State<ComponentProps>> { | ||
state: State<ComponentProps>; | ||
setProps(props: Partial<ComponentProps>): void; | ||
render(): ReactElement<any, string | import("react").JSXElementConstructor<any>>; | ||
} | ||
export declare const TestRenderer: <ComponentProps>(props: Props<ComponentProps> & { | ||
ref?: Ref<ImperativeApi<ComponentProps>> | undefined; | ||
}) => ReactElement | null; | ||
export {}; | ||
//# sourceMappingURL=TestRenderer.d.ts.map |
@@ -6,10 +6,16 @@ "use strict"; | ||
const defaultRender = (element) => element; | ||
exports.TestRenderer = react_1.forwardRef(({ children, render = defaultRender }, ref) => { | ||
const [props, setProps] = react_1.useState(); | ||
react_1.useImperativeHandle(ref, () => ({ | ||
setProps(newProps) { | ||
setProps(newProps); | ||
}, | ||
})); | ||
return render(props ? react_1.cloneElement(children, props) : children); | ||
}); | ||
class TestRenderer extends react_1.Component { | ||
constructor() { | ||
super(...arguments); | ||
this.state = {}; | ||
} | ||
setProps(props) { | ||
this.setState({ props }); | ||
} | ||
render() { | ||
const { props } = this.state; | ||
const { children, render = defaultRender } = this.props; | ||
return render(props ? react_1.cloneElement(children, props) : children); | ||
} | ||
} | ||
exports.TestRenderer = TestRenderer; |
{ | ||
"name": "@quilted/react-testing", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"description": "", | ||
@@ -74,3 +74,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "99da19af59ea8140b89c613091d0e658ec8ffbf9" | ||
"gitHead": "3e014d6936f0368e2b4cdac487c7fb5745bf4ee5" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
552170
5757