New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

component-mock

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

component-mock

> A wrapper for deku components to facilitate easier unit-testing.

latest
npmnpm
Version
0.1.0
Version published
Weekly downloads
16
Maintainers
1
Weekly downloads
 
Created
Source

component-mock

A wrapper for deku components to facilitate easier unit-testing.

Usage

var Mock = require('component-mock');

var Component = {
  defaultProps: {
    name: 'a'
  },
  render: function ({ props }) {
    return <div>{props.name}</div>;
  }
}

var mock = Mock(Component);

var node = mock.render();
assert.isNode(node, 'div');
assert.hasChildren(node, [ 'a' ]);

var node = mock.render({ props: { name: 'b' } });
assert.isNode(node, 'div');
assert.hasChildren(node, [ 'b' ]);

Mock(Component)

Returns a wrapper object for the Component. The goal is that there will be many methods that reflect various lifecycle events for the deku component. Currently, we only deal with render, but others will be added over time as we develop good testing strategies.

mock.render(component)

Calls Component.render(). The render function will have all the parameters it would normally expect generated automatically. (eg: props, props.children and state)

This also uses Component.defaultProps and Component.initialState() to ensure the component object is generated accurately.

The setState function that is passed is simply a no-op, it won't trigger any other changes. (as it shouldn't, since this is designed for unit-testing)

FAQs

Package last updated on 03 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts