How to use the react-test-renderer/shallow function in react-test-renderer

To help you get started, we’ve selected a few react-test-renderer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airbnb / enzyme / packages / enzyme-adapter-react-16.3 / src / ReactSixteenThreeAdapter.js View on Github external
createShallowRenderer(/* options */) {
    const adapter = this;
    const renderer = new ShallowRenderer();
    let isDOM = false;
    let cachedNode = null;
    return {
      render(el, context, {
        providerValues = new Map(),
      } = {}) {
        cachedNode = el;
        /* eslint consistent-return: 0 */
        if (typeof el.type === 'string') {
          isDOM = true;
        } else if (isContextProvider(el)) {
          providerValues.set(el.type, el.props.value);
          const MockProvider = Object.assign(
            (props) => props.children,
            el.type,
          );
github airbnb / enzyme / packages / enzyme-adapter-react-15 / src / ReactFifteenAdapter.js View on Github external
createShallowRenderer(/* options */) {
    const renderer = new ShallowRenderer();
    let isDOM = false;
    let cachedNode = null;
    return {
      render(el, context) {
        cachedNode = el;
        /* eslint consistent-return: 0 */
        if (typeof el.type === 'string') {
          isDOM = true;
        } else {
          isDOM = false;
          return withSetStateAllowed(() => renderer.render(el, context));
        }
      },
      unmount() {
        renderer.unmount();
      },
github FreeFeed / freefeed-react-client / test / unit / components / post-likes.js View on Github external
it(`should render ${i} likes if nothing is omitted`, () => {
      const post = { omittedLikes: 0 };

      const renderer = new ShallowRenderer();
      renderer.render();

      const errorBoundary = renderer.getRenderOutput().props.children;
      expect(errorBoundary.props.children[1].props.children, 'to have length', i);
    });
  }
github topcoder-platform / community-app / __tests__ / shared / components / Settings / Account / index.jsx View on Github external
import React from 'react';
import Renderer from 'react-test-renderer/shallow';

import Account from 'components/Settings/Account';

import userProfile from '../__mocks__/user-profile.json';
import profileState from '../__mocks__/profile-state.json';

const rnd = new Renderer();

const settingsUI = {
  TABS: {
    ACCOUNT: {
      MYACCOUNT: 'my account',
      LINKEDACCOUNT: 'linked account',
    },
  },
};

it('renders account setting page correctly', () => {
  rnd.render((
github topcoder-platform / community-app / __tests__ / shared / components / Contentful / TracksFilter / TracksFilter.jsx View on Github external
test('Matches shallow shapshot', () => {
  const renderer = new Renderer();
  const MOCK_PROPS = {
    theme: {},
    startDate: '2019-08-01T07:21:20.249Z',
    endDate: '2019-09-01T07:21:20.249Z',
  };
  renderer.render();
  expect(renderer.getRenderOutput()).toMatchSnapshot();
});
github topcoder-platform / community-app / __tests__ / shared / components / Content.jsx View on Github external
test('Matches shallow shapshot', () => {
  const renderer = new Renderer();
  renderer.render(<content>);
  expect(renderer.getRenderOutput()).toMatchSnapshot();
});
</content>
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / MiniCart / __tests__ / cartOptions.spec.js View on Github external
import React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow';

import CartOptions from '../cartOptions';

const renderer = new ShallowRenderer();

test('it renders the correct tree', () => {
    const props = {
        cartItem: {
            item_id: 99,
            name: 'cartItem name',
            price: 99,
            qty: 99
        },
        configItem: {
            __typename: 'simple'
        },
        currencyCode: 'USD',
        endEditItem: jest.fn(),
        updateCart: jest.fn()
    };
github kensho-technologies / orama / test / helpers / shallowRender.js View on Github external
export default function shallowRender(element) {
  const renderer = new ReactShallowRenderer()
  renderer.render(element)
  return renderer.getRenderOutput()
}
github topcoder-platform / community-app / __tests__ / shared / containers / SubmissionManagement.jsx View on Github external
import _ from 'lodash';
import React from 'react';
import Rnd from 'react-test-renderer/shallow';
import TU from 'react-dom/test-utils';

const rnd = new Rnd();

const mockChallengeActions = {
  challenge: {
    getDetailsInit: jest.fn(),
    getDetailsDone: jest.fn(),
    getSubmissionsInit: jest.fn(),
    getSubmissionsDone: jest.fn(),
  },
};
jest.setMock(require.resolve('actions/challenge'), mockChallengeActions);

const mockSmpActions = {
  smp: {
    cancelDelete: jest.fn(),
    confirmDelete: jest.fn(),
    deleteSubmissionDone: jest.fn(),
github mobxjs / mobx-state-tree / packages / mst-example-redux-todomvc / src / components / TodoItem.spec.js View on Github external
const setup = (editing = false) =&gt; {
    const props = {
        todo: {
            id: 0,
            text: "Use Redux",
            completed: false
        },
        editTodo: jest.fn(),
        deleteTodo: jest.fn(),
        completeTodo: jest.fn()
    }

    const renderer = new ShallowRenderer()

    renderer.render()

    let output = renderer.getRenderOutput()

    if (editing) {
        const label = output.props.children.props.children[1]
        label.props.onDoubleClick({})
        output = renderer.getRenderOutput()
    }

    return {
        props: props,
        output: output,
        renderer: renderer
    }