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

composable-form-tests

v1.1.0

Published

Tests for Composable Form Spec components written in React

Downloads

1,411

Readme

Composable Form Tests

Exposes functions that test your React components to ensure they correctly implement the Composable Form Spec. Assumes a Jest test environment and requires a peer dev dependency of enzyme.

Installation

$ npm i --save-dev composable-form-tests jest-cli babel-jest enzyme

How to Test an "Input" Component

In your input tests file, which will be run by Jest:

import React from 'react';
import { mount } from 'enzyme';
import { testInput } from 'composable-form-tests';
import MyInputComponent from './MyInputComponent';

testInput({
  component: MyInputComponent,
  mount,
  ...<other options>
});

testInput Options

| component | REQUIRED. The component class that you are testing, which you intend to conform to the Composable Form "Input" Specification | |------------------|------------------------------------------------------------------------------------------------------------------------------| | defaultValue | REQUIRED. The value that your component has when neither the user nor the containing Form passes in a value prop | | exampleValueOne | REQUIRED. A value that would make sense for your input. Must be different from the defaultValue and from exampleValueTwo | | exampleValueTwo | REQUIRED. A value that would make sense for your input. Must be different from exampleValueTwo. | | mount | REQUIRED. The mount function imported from enzyme package | | options | OPTIONAL. If your input takes options, the options array. | | props | OPTIONAL. A props object that should be used as props on the input for all tests | | simulateChanging | OPTIONAL. If your input ever calls onChanging, use this function to simulate one user action that will cause it to happen. | | simulateChanged | REQUIRED. Use this function to simulate one user action that will cause onChange to be called. | | simulateSubmit | OPTIONAL. If your input ever calls onSubmit, use this function to simulate one user action that will cause it to happen. | | testGetValue | OPTIONAL. Default is false. Set to true to add a test for the getValue() instance function | testIsDirty | OPTIONAL. Default is false. Set to true to add a test for the isDirty() instance function | testResetValue | OPTIONAL. Default is false. Set to true to add a test for the resetValue() instance function | testSetValue | OPTIONAL. Default is false. Set to true to add a test for the setValue() instance function

Basic Input Example

import React from 'react';
import { mount } from 'enzyme';
import { testInput } from 'composable-form-tests';
import Input from './Input';

testInput({
  component: Input,
  defaultValue: null,
  exampleValueOne: 'ONE',
  exampleValueTwo: 'TWO',
  mount,
  simulateChanging(wrapper, value) {
    // Refer to Enzyme documentation
    wrapper.find('input').simulate('change', { target: { value } });
  },
  simulateChanged(wrapper, value) {
    // Refer to Enzyme documentation
    wrapper.find('input').simulate('blur', { target: { value } });
  },
  simulateSubmit(wrapper) {
    // Refer to Enzyme documentation
    wrapper.find('input').simulate('keypress', { which: 13 });
  },
});

Select Input Example

import React from 'react';
import { mount } from 'enzyme';
import { testInput } from 'composable-form-tests';
import SelectInput from './SelectInput';

testInput({
  component: SelectInput,
  defaultValue: null,
  exampleValueOne: 'a',
  exampleValueTwo: 'b',
  mount,
  options: [
    { label: 'A', value: 'a' },
    { label: 'B', value: 'b' },
    { label: 'C', value: 'c' },
  ],
  simulateChanged(wrapper, value) {
    // Refer to Enzyme documentation
    wrapper.find('select').simulate('change', { target: { value } });
  },
});