underdog-mocha-react

1.5.0 • Public • Published

underdog-mocha-react

Utilities for testing React applications with Mocha. Includes enzyme, jsdom, and react-addons-test-utils.

Usage

  1. Install with npm.
npm install underdog-mocha-react --save
  1. Import and use in your test.
import React from 'react';
import assert from 'assert';
import reactUtils from 'underdog-mocha-react';

describe('A sufficiently thorough test', function () {
  // Returns a helper method for rendering elements with enzyme.mount, render().
  // Also creates a fake dom with jsdom, accessible from global.window.
  const {render, simulateDOMEvent} = reactUtils();

  it('confirms all the things', function () {
    // Render component render() to get an Enzyme wrapper via enzyme.mount().
    const wrapper = render(
      <a href="/test">Hey there</a>
    );

    // You also get a fake window object for your tests.
    // This is useful for simulating events with wrapper.find('...').simulate().
    assert.notEqual(typeof window, 'undefined');

    // Test how your component reacts to DOM events with simulateDOMEvent()
    simulateDOMEvent(document, 'keydown', {
      keyCode: 27
    });
  });
});

Dependents (0)

Package Sidebar

Install

npm i underdog-mocha-react

Weekly Downloads

0

Version

1.5.0

License

MIT

Unpacked Size

6.11 kB

Total Files

6

Last publish

Collaborators

  • restlessbit