mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
fix rest types
This commit is contained in:
@@ -112,7 +112,7 @@ function makeDebug(renderer: Root): DebugFunction {
|
||||
function debugImpl(options?: DebugOptions) {
|
||||
const { defaultDebugOptions } = getConfig();
|
||||
const debugOptions = { ...defaultDebugOptions, ...options };
|
||||
const json = renderer.toJSON();
|
||||
const json = renderer.container.toJSON();
|
||||
if (json) {
|
||||
return debug(json, debugOptions);
|
||||
}
|
||||
|
||||
@@ -5,25 +5,26 @@ type JsonPropsMapper = {
|
||||
};
|
||||
|
||||
export function mapJsonProps<T extends JsonNode | JsonNode[] | null>(
|
||||
element: T,
|
||||
node: T,
|
||||
mapper: JsonPropsMapper,
|
||||
): T {
|
||||
if (Array.isArray(element)) {
|
||||
return element.map((e) => mapJsonProps(e, mapper)) as T;
|
||||
if (Array.isArray(node)) {
|
||||
return node.map((e) => mapJsonProps(e, mapper)) as T;
|
||||
}
|
||||
|
||||
if (!element) {
|
||||
return element;
|
||||
if (!node || typeof node === 'string') {
|
||||
return node;
|
||||
}
|
||||
|
||||
const resultProps = { ...element.props };
|
||||
const resultProps: Record<string, unknown> = { ...node.props };
|
||||
Object.keys(mapper).forEach((key) => {
|
||||
if (key in element.props) {
|
||||
if (key in node.props) {
|
||||
resultProps[key] = mapper[key];
|
||||
}
|
||||
});
|
||||
|
||||
const resultElement = { ...element, props: resultProps };
|
||||
// @ts-expect-error: TODO fix type
|
||||
const resultElement = { ...node, props: resultProps };
|
||||
Object.defineProperty(resultElement, '$$typeof', {
|
||||
value: Symbol.for('react.test.json'),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user