JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3896
  • Score
    100M100P100Q118658F
  • License ISC

The module is temporary workaround for passing context for shallow rendering

Package Exports

  • shallow-with-context

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shallow-with-context) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

shallow-with-context

Build Status dependencies Status Coverage Status NPM package version code style: prettier

The module is temporary workaround for passing context in shallow rendering mode. The new React Context API is not supported in shallow rendering mode yet.

It use under hood Legacy Context API.

Installation

npm i shallow-with-context --save-dev

Usage

import { shallow } from 'enzyme';
import { withContext } from 'shallow-with-context';
import React from 'react';

const MyContext = React.createContext({ text: 'default' });
class Component extends React.Component {
  static contextType = MyContext;
  render() {
    return <div>{this.context.text}</div>
  }
}

describe('your description', () => {
  it('your spec', () => {
    const context = { text: 'new value' };
    const ComponentWithContext = withContext(Component, context);

    const wrapper = shallow(ComponentWithContext, { context });

    expect(wrapper).toMatchInlineSnapshot('<div>new value</div>');
  });
});

API

withContext

Parameters

  • Component (React.Component|React.PureComponent|function)
  • context Object<string, *>