forked from callstack/react-native-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.js
42 lines (38 loc) · 1010 Bytes
/
debug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// @flow
/* eslint-disable no-console */
import * as React from 'react';
import render from './render';
import debugShallow from './helpers/debugShallow';
import debugDeep from './helpers/debugDeep';
import format from './helpers/format';
/**
* Log pretty-printed deep test component instance
*/
function debugDeepElementOrInstance(
instance: React.Element<any> | ?ReactTestRendererJSON,
message?: any = ''
) {
try {
// We're assuming React.Element<any> here and fallback to
// rendering ?ReactTestRendererJSON
// $FlowFixMe
const { toJSON } = render(instance);
if (message) {
console.log(`${message}\n\n`, format(toJSON()));
} else {
console.log(format(toJSON()));
}
} catch (e) {
// $FlowFixMe
debugDeep(instance);
}
}
function debug(
instance: ReactTestInstance | React.Element<any>,
message?: any
) {
return debugShallow(instance, message);
}
debug.shallow = debugShallow;
debug.deep = debugDeepElementOrInstance;
export default debug;