How to use react-test-renderer - 10 common examples

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 conveyal / analysis-ui / lib / components / modifications-map / __tests__ / stop-select-polygon.js View on Github external
it('renders correctly', () => {
    const props = {
      routeStops: [{
        stop_id: '1',
        stop_lat: 12,
        stop_lon: 34,
        stop_name: 'mock gtfs stop'
      }],
      selectStops: jest.fn()
    }

    // mount component
    const tree = renderer
      .create(
        <map>
          
        </map>
      )
      .toJSON()
    expect(tree).toMatchSnapshot()

    const noCalls = ['selectStops']
    noCalls.forEach(fn =&gt; {
      expect(props[fn]).not.toBeCalled()
    })
  })
})
github GitbookIO / unstated / __tests__ / unstated.tsx View on Github external
const counter = new CounterContainer();
    const tree = renderer.create(
        
            
        
    );

    renderer.act(() =&gt; {
        const el: any = tree
            .toJSON()
            .children.find(({ props = {} }) =&gt; props.id === 'offset-text');
        expect(el.children).toEqual(['0']);
    });

    // This update should not trigger a re-render
    renderer.act(() =&gt; {
        counter.increment();
    });

    renderer.act(() =&gt; {
        const el: any = tree
            .toJSON()
            .children.find(({ props = {} }) =&gt; props.id === 'offset-text');
        expect(el.children).toEqual(['0']);
    });

    // This update should trigger a re-render
    renderer.act(() =&gt; {
        counter.setOffset(10);
    });

    renderer.act(() =&gt; {
github coralproject / talk / src / core / client / framework / testHelpers / act.ts View on Github external
export default function act(callback: () =&gt; T): T {
  let callbackResult: T;
  const actResult = TestRenderer.act(() =&gt; {
    callbackResult = callback();
    return callbackResult as any;
  });
  if (isPromiseLike(callbackResult!)) {
    // Return it this way, to preserve warnings that React emits.
    return {
      then(resolve: (value: any) =&gt; void, reject: (err?: Error) =&gt; void) {
        (actResult as PromiseLike).then(() =&gt; {
          resolve(callbackResult);
        }, reject);
      },
    } as any;
  }
  return callbackResult!;
}
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 conorhastings / react-syntax-highlighter / __tests__ / render-plain-string.js View on Github external
test('SyntaxHighlighter renders childre unadultered when no language disocvered in highlight auto', () =&gt; {
  const tree = renderer
    .create(
      
        {`Contacts* contacts = [[Contacts alloc]init];`}
      
    )
    .toJSON();
  expect(tree).toMatchSnapshot();
});
github FaridSafi / react-native-gifted-form / example / __tests__ / index.ios.js View on Github external
it('renders correctly', () =&gt; {
  const tree = renderer.create(
    
  );
});
github bcgov / tfrs / frontend / __tests__ / app / components / StatusInterceptor.js View on Github external
test('StatusInterceptor should display the proper message for 401 errors', () =&gt; {
  const statusCode = 401;
  const component = renderer.create();

  const tree = component.toJSON();
  expect(tree).toMatchSnapshot();
});
github parkerziegler / github-search / __tests__ / components / Primitives / Error.spec.js View on Github external
it('renders correctly with all required props', () =&gt; {
    const tree = renderer.create().toJSON();
    expect(tree).toMatchSnapshot();
  });
github twilio / TwilioChatJsReactNative / __tests__ / index.js View on Github external
it('renders correctly', () =&gt; {
  const tree = renderer.create(
    
  );
});