Coder Social home page Coder Social logo

avmcrae / enzyme-context Goto Github PK

View Code? Open in Web Editor NEW

This project forked from trialspark/enzyme-context

0.0 1.0 0.0 12.1 MB

A pluggable library which simplifies the process of testing components that rely on react context.

Home Page: https://trialspark.gitbook.io/enzyme-context/

License: MIT License

JavaScript 1.89% TypeScript 98.11%

enzyme-context's Introduction

enzyme-context

Build Status Coverage Status

Enzyme Context is a pluggable library which simplifies the process of testing components that rely on react context.

Basic Usage

test-utils/enzyme.ts

import { createMount, createShallow } from 'enzyme-context';
import { reduxContext } from 'enzyme-context-redux';
import { routerContext } from 'enzyme-context-react-router-4';
import { createStore } from 'redux';
import reducer from './reducer'; // this is _your_ app's main reducer

const plugins = {
  store: reduxContext({
    createStore: () => createStore(reducer),
  }),
  history: routerContext(),
};

export const mount = createMount(plugins);
export const shallow = createShallow(plugins);

MyComponent.spec.tsx

import { mount } from '../test-utils/enzyme'; // import from the module defined above
import MyComponent from './MyComponent';

// this example uses jest, but that isn't required!
describe('MyComponent', () => {
  let component;
  let store;
  let history;

  beforeEach(() => {
    // mount() returns an object with the mounted EnzymeWrapper component and each of the specified plugins.
    // In this example, it returns:
    //   - component: the mounted EnzymeWrapper
    //   - store: provided by the reduxContext plugin, a redux store
    //   - history: provided by the routerContext plugin, a history object for URL manipulation
    ({ component, store, history } = mount(<MyComponent />));
  });

  it('responds to redux state changes', () => {
    store.dispatch({ type: 'SOME_ACTION' });
    component.update();
    expect(component.text()).toBe('...');
  });

  it('responds to location changes', () => {
    history.push('/my/new/url');
    component.update();
    expect(component.text()).toBe('...');
  });
});

Official Plugins

Enzyme Context maintains a few official plugins for some popular react libraries:

enzyme-context's People

Contributors

minznerjosh avatar dependabot[bot] avatar doronshapiro avatar jkillian avatar mrjaeger avatar avmcrae avatar glentakahashi avatar leothekim avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.