jrwebdev / ngreact-test-utils

Test utilities for Angular apps using React and ngReact
MIT License
4 stars 0 forks source link

ngreact-test-utils

Utilities for testing Angular directives which contain React components with ngReact.

These utilities are not for testing React components directly - for that I would recommend using Enzyme.

npm version Build Status

Sauce Test Status

ngreact-test-utils provides two functions - compile() and simulate():

Installation

npm i -D ngreact-test-utils

Usage

import {simulate, compile} from 'ngreact-test-utils';

Both angular and angular-mocks must be loaded to use.

See the test/ directory for example usage

API Documentation

compile(el, [scope])

Compiles an Angular directive and flushes $timeout in order to compile any ngReact directives

Arguments

  1. el (string) Element to compile
  2. scope (object) Values to add to the directive's scope

Returns

(Object) Object containing the following:

simulate (el, event, [eventData])

Fires both .triggerHandler() on the element for Angular and generates a Synthetic Event for React using React Test Utils' simulate() method.

Arguments

  1. el (HTMLElement|Object) Raw DOM Node or Angular element to fire the event on
  2. event (string) Event to fire. Can either be in lowercase or using React's lower camelCase conventions - the appropriate conversion will occur internally
  3. eventData (Object) Additional data to pass to the event.

A number of convenience methods are also available for simulate for common events. For all other events, or for additional flexibility, use simulate() directly.

simulate.click(el, [eventData])

simulate.mouseOver(el, [eventData])

simulate.mouseOut(el, [eventData])

simulate.keyUp(el, keyCode, [eventData])

simulate.keyDown(el, keyCode, [eventData])

simulate.keyPress(el, keyCode, [eventData])

simulate.focus(el, [eventData])

simulate.blur(el, [eventData])

simulate.change(el, value, [eventData])