@shopify/enzyme-utilities
Enzyme utilities for testing React components
Last updated 2 months ago by shopify-dep .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @shopify/enzyme-utilities 
SYNC missed versions from official npm registry.

@shopify/enzyme-utilities

Build Status License: MIT npm version

Enzyme utilities for testing React components.

Note: as of version 2.0, this library requires react and react-dom to be at least version 16.8.x.

Installation

$ yarn add @shopify/enzyme-utilities

API Reference

function trigger(wrapper: any, keypath: string, ...args: any[]): any

Triggers the callback in the props of wrapper according to the keypath and with the provided args.

Example Usage

import React from 'react';
import MyComponent, {Button, Thing} from '../MyComponent';
import {mount} from 'enzyme';
import {trigger} from '@shopify/enzyme-utilities';

describe('<MyComponent />', () => {
  it('shows a Thing when its Button it clicked', () => {
    const myComponent = mount(<MyComponent />);
    trigger(myComponent.find(Button), 'onAction');

    expect(myComponent.find(Thing)).toHaveLength(1);
  });
});

Usage with asynchronous callbacks

The trigger function automatically handles updating the Enzyme instance both immediately as well as after the promise has resolved:

import React from 'react';
import MyComponent, {Button, Thing} from '../MyComponent';
import {mount} from 'enzyme';
import {trigger} from '@shopify/enzyme-utilities';

describe('<MyComponent />', () => {
  it('shows a Thing after a pause when its Button it clicked', () => {
    const myComponent = mount(<MyComponent />);
    const pause = trigger(myComponent.find(Button), 'onAction');
    expect(myComponent.find(Thing)).toHaveLength(0);

    await pause;
    expect(myComponent.find(Thing)).toHaveLength(1);
  });
});

Current Tags

  • 2.1.13                                ...           latest (2 months ago)
  • 1.0.0-sknext-beta.2                                ...           next (5 days ago)

37 Versions

  • 1.0.0-sknext-beta.2                                ...           5 days ago
  • 1.0.0-sknext-beta.1                                ...           9 days ago
  • 2.1.13-sknext-beta.9                                ...           10 days ago
  • 0.0.8-sknext-beta.8                                ...           11 days ago
  • 0.0.2-sknext-beta.2                                ...           16 days ago
  • 0.0.1-sknext-beta.1                                ...           16 days ago
  • 2.1.13                                ...           2 months ago
  • 2.1.12                                ...           3 months ago
  • 2.1.11                                ...           3 months ago
  • 2.1.10                                ...           3 months ago
  • 2.1.9                                ...           6 months ago
  • 2.1.8                                ...           7 months ago
  • 2.1.7                                ...           9 months ago
  • 2.1.6                                ...           9 months ago
  • 2.1.5                                ...           10 months ago
  • 2.1.4                                ...           a year ago
  • 2.1.3                                ...           a year ago
  • 2.1.2                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.3                                ...           a year ago
  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.1.7                                ...           a year ago
  • 1.1.6                                ...           2 years ago
  • 1.1.4                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
Downloads
Today 0
This Week 11
This Month 55
Last Day 0
Last Week 34
Last Month 19
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |