All files / src/test withContext.js

50% Statements 1/2
100% Branches 0/0
50% Functions 1/2
50% Lines 1/2
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                                        14x                                        
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
import { mount, shallow } from 'enzyme';
 
/**
 * Mounts the only child with the context of the current element.
 * @param {object} reactElement - element to mount the children from
 *
 * This is very useful for convenience in tests, with the following pattern:
 * <Provider ... />
 *    <MyComponent />
 * </Provider
 */
export function mountWithContext(reactElement) {
  return mount(reactElement.getElement(), {
    context: reactElement.instance().getChildContext(),
    childContextTypes: reactElement.instance().constructor.childContextTypes,
  });
}
/**
 * Dive shallowly into the only child with the context of the current element.
 * @param {object} reactElement - element to mount the children from
 *
 * This is very useful for convenience in tests, with the following pattern:
 * <Provider ... />
 *    <MyComponent/>
 * </Provider
 */
export function diveWithContext(reactElement) {
  return reactElement.dive({
    context: reactElement.instance().getChildContext(),
    childContextTypes: reactElement.instance().constructor.childContextTypes,
  });
}