Giter Site home page Giter Site logo

jsx-test's Introduction

jsx-test

npm version Build Status Dependency Status devDependency Status

jsx-test is a tool that makes it easy to test '.jsx' files and includes some helpers for testing react components.

The main features of jsx-test are:

  • Includes some helpers to simplify the test of React Components.
  • Assertion methods to check the component renders the correct html based on the given props.
  • Does NOT automock your dependencies.
  • Is much simpler and faster than Jest.
  • Works with mocha, jasmine or any other test framework.

Note: If you would like to require jsx files directly please follow these instructions

Install

npm install --save-dev jsx-test

Usage

simulateEvent

simulateEvent(ReactComponent element, String event, Object? eventData)
simulateEvent(DOMElement element, String event, Object? eventData)

Simulates an event on an element.

renderComponent

ReactElement renderComponent(ReactComponent comp, Object? props, any? children)

Renders a component w/ its props and children.

unmountComponent

Boolean unmountComponent(ReactComponent comp)

Unmount a component.

elementQuerySelector

DOMElement elementQuerySelector(ReactComponent comp, String selector)

Gets 1st child of comp using selector selector

elementQuerySelectorAll

DOMElement[] elementQuerySelectorAll(ReactComponent comp, String selector)

Gets children of comp using selector selector

stubComponent

ReactComponent stubComponent(ReactElement tag, any? children, boolean? showDataProps)
ReactComponent stubComponent(String tag, any? children, boolean? showDataProps)

Creates a stub component with tag and its children. If showDataProps is true, all props will be set in the rendered DOMElement in the form of data-<propKey> = <propValue>.

withContext

ReactComponent withContext(ReactComponent Component, Object context)

Wraps component in a context creating component.

assertRender

assertRender(ReactComponent Component, Object props, String expectedHTML)

Assert component render matches the expectedHTML. The expectedHTML regex conversion can be seen here.

assertNotRender

assertNotRender(ReactComponent Component, Object props, String unexpectedHTML)

The reverse of assertRender.

Example

Check our examples and tests.

jsx-test's People

Contributors

3den avatar akshayp avatar brucewpaul avatar cvan avatar davglass avatar hankhsiao avatar jeffkole avatar mayank-hey avatar mi94 avatar redonkulus avatar roderickhsiao avatar ryansukale avatar stanleyhlng avatar tinorzldn avatar zeikjt 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.