npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dce-enzyme

v1.0.19

Published

React component unit testing package that wraps Enzyme.

Downloads

26

Readme

dce-enzyme

React component unit testing package that wraps Enzyme.

Writing a Test

Import dependencies at top of test

import React from 'react';
import Driver from 'dce-enzyme';

Write your test

Initialize the driver with the component to test then use driver functions (see the full list below) to write your test

...
import OkayButton from './OkayButton';

describe('OkayButton', () => {
  it('Handles a Click', async () => {
    // Keep track of button clicks
    let clicked = false;

    // Initialize the driver
    const driver = new Driver(
      <OkayButton
        title="I am Done"
        color="blue"
        onClick={() => { clicked = true; }}
      />
    );

    // Simulate a click
    await driver.click('button');

    // Make sure the button was clicked
    assert(clicked, 'The button did not call onClick');
  });
});

Driver functions

Note: wherever you see "selector," this can be a CSS selector, React component constructor, React component display name, object property selector, or any other valid enzyme selector.

click(selector) – clicks the given element

Example:

driver.click('#close-button');

focus(selector) - focuses the given element

Example:

driver.click('#selectable-element');

toggleCheckbox(selector) - simulates someone toggling a checkbox

Example:

driver.toggleCheckbox('#agree');

typeInto(selector, text) – types the given text into the element

Example:

await driver.typeInto('#email-field', '[email protected]');

getAttributes(selector) – returns an object holding all the attributes of the element

Example:

const att = driver.getAttributes('#email-field');
const email = att.value;

assert(email.includes('@'), 'Email does not include "@"');

getHTML(selector) – returns the HTML representation of the element

Example:

const html = driver.getHTML('#okay-button');

assert(html.includes('some-html-content'));

elementExists(selector) – returns true if the given element exists

Example:

assert(driver.elementExists('#submit'), 'Submit button absent');

getText(selector) – returns the text inside an element

Example:

assert.equal(
  driver.getText('span'),
  'About Me',
  'Span text was incorrect'
);

getState() – returns the state of the root-level component

Example:

const state = driver.getState();

assert.equal(
  state.numClicks,
  10,
  'The number of clicks in the state is wrong!'
);

waitForElementToExist(selector, [timeoutSecs = 2]) – waits for an element to exist

Waits until the element exists.

waitForStatePropToEqual(prop, value, [timeoutSecs = 2]) – waits for a property of the root-level component's state to equal the given value

Arguments:

  • prop – the state property to check
  • value – wait for the prop to equal this value
  • timeoutSecs – the number of seconds to wait until throwing a timeout error

Example:

// Wait up to 1min for the component to load
await driver.waitForStatePropToEqual('status', 'loaded', 60);