1.5.0 • Published 5 years ago

underdog-mocha-react v1.5.0

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

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
  2. 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
        });
      });
    });
1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago