Skin-Deep React Testing Utilities

1.2.0 · abandoned · verified Tue Apr 21

Skin-Deep provides testing helpers built on top of React's shallow rendering test utilities. Its primary goal is to offer higher-level functionality for unit testing React components, allowing developers to assert on a component's rendered output without fully mounting it or its children. The current stable version is 1.2.0. This library was designed to work with React versions 0.14 and above, requiring specific React testing utility packages depending on the React version (e.g., `react-addons-test-utils` for <15.5 or `react-test-renderer` for >=15.5). Skin-Deep offers methods to extract portions of the rendered tree, trigger events, and dive into sub-trees, providing a structured way to interact with a shallow-rendered component's virtual DOM. Its release cadence is effectively inactive, with the last update several years ago, making it unsuitable for modern React applications (React 18+).

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to shallow render a React component using `skin-deep`, then extract a specific sub-tree based on a selector and prop matcher, and finally perform assertions on its type, props, and text content.

import React from 'react';
import * as sd from 'skin-deep';
import assert from 'assert';

// Define a simple React component
class MyComponent extends React.Component {
  render() {
    return (
      <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/abc">Draw</a></li>
        <li><a href="/def">Away</a></li>
      </ul>
    );
  }
}

// Shallow render the component
const tree = sd.shallowRender(<MyComponent />);

// Find a specific sub-tree using a selector and matcher
const homeLink = tree.subTree('a', { href: '/' });

// Assertions on the extracted sub-tree
assert.equal(homeLink.type, 'a');
assert.equal(homeLink.props.href, '/');
assert.equal(homeLink.text(), 'Home');

console.log('Shallow rendering and assertions successful!');

view raw JSON →