GithubHelp home page GithubHelp logo

underdogio / mocha-react Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 263 KB

Utilities for testing React applications with Mocha.

Home Page: https://npmjs.com/package/underdog-mocha-react

JavaScript 100.00%

mocha-react's Introduction

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
    });
  });
});

mocha-react's People

Contributors

chriscauley avatar realplatanopapi avatar restlessbit avatar

Stargazers

 avatar

Watchers

 avatar  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.