🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

react-test-utils

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-test-utils

export the react test utils to single package

latest
npmnpm
Version
0.0.1
Version published
Weekly downloads
40
-48.05%
Maintainers
1
Weekly downloads
 
Created
Source

React Test Utils

ReactTestUtils from facebook ReactTestUtils, export it as a single repo, just make it more easy to included in and testing your React components.

eg:

/** @jsx React.DOM **/

var React = require('react/addons');
require('react-test-utils');
// or var ReactTestUtils = require('react-test-utils');
var test = require('tape');
var Player = require('../../js/Player');
var sinon = require('sinon');
var ReactTestUtils = React.addons.ReactTestUtils;

var onMusicAdd = sinon.spy();

test('Player', function(t) {
  var player = <Player test='testing' />;
  ReactTestUtils.renderIntoDocument(player);
  t.plan(1);
  t.equal(player.props.test, 'testing', 'test property should exists');
});

test('Player: simulate drag music', function(t) {
  var player = <Player test='testing' onMusicAdd={onMusicAdd}/>;
  var files = [
    {name: 'test.mp3', type: 'audio/mp3'}
  ];
  var fakeEvt = {
    dataTransfer: {
      files: files
    }
  };
  ReactTestUtils.renderIntoDocument(player);

  t.plan(3);

  ReactTestUtils.Simulate.drop(player.refs.el);
  t.notOk(onMusicAdd.called, 'onMusicAdd should not be called');

  ReactTestUtils.Simulate.drop(player.refs.el, fakeEvt);
  t.ok(onMusicAdd.called, 'onMusicAdd should be called');
  t.ok(onMusicAdd.calledWith(files), 'onMusicAdd shoule be called with mock files');
});

just copy the ReactTestUtils from the facebook/react project, :p it works!

Keywords

react

FAQs

Package last updated on 02 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts