main
js 25 lines 850 Bytes
Raw
1 import {printStore} from 'react-devtools-shared/src/devtools/utils';
2
3 // `test` is part of Jest's serializer API
4 export function test(maybeState) {
5 if (maybeState === null || typeof maybeState !== 'object') {
6 return false;
7 }
8
9 const hasOwnProperty = Object.prototype.hasOwnProperty.bind(maybeState);
10 // Duck typing at its finest.
11 return (
12 hasOwnProperty('inspectedElementID') &&
13 hasOwnProperty('ownerFlatTree') &&
14 hasOwnProperty('ownerSubtreeLeafElementID')
15 );
16 }
17
18 // print() is part of Jest's serializer API
19 export function print(state, serialize, indent) {
20 // This is a big of a hack but it works around having to pass in a meta object e.g. {store, state}.
21 // DevTools tests depend on a global Store object anyway (initialized via setupTest).
22 const store = global.store;
23
24 return printStore(store, false, state);
25 }