inferno-test-utils
TypeScript icon, indicating that this package has built-in type declarations

8.2.3 • Public • Published

inferno-test-utils

Suite of utilities for testing Inferno applications

Install

npm install inferno --save
npm install inferno-test-utils --save-dev

Contents

Usage

renderIntoContainer(vNodeTree)

Renders vNodeTree into a detached DOM element in the document and returns a rendered VNode tree.

This function requires a DOM. JEST can provide this for you.

const vNodeTree = (
  <div className="outer">
    <SomeComponent className="inner"/>
  </div>
);
const renderedTree = renderIntoContainer(vNodeTree);

findAllInRenderedTree(renderedTree, predicate)

Calls predicate with each VNode instance in renderedTree.

Returns an array of VNodes where predicate returns true.

const vNodeTree = (
  <div className="outer">
    <SomeComponent className="inner"/>
  </div>
);
const renderedTree = render(vNodeTree, DOM);
const predicate = (vNode) => vNode.type === SomeComponent;
const result = findAllInRenderedTree(renderedTree, predicate);

findAllInVNodeTree(vNodeTree, predicate)

Calls predicate with each VNode instance in vNodeTree.

Returns an array of VNodes where predicate returns true.

const vNodeTree = (
  <div className="outer">
    <SomeComponent className="inner"/>
  </div>
);
const predicate = (vNode) => vNode.type === SomeComponent;
const result = findAllInVNodeTree(vNodeTree, predicate);

scryRenderedDOMElementsWithClass(renderedTree, classNames)

Returns an array of DOM elements with classNames.

classNames can be a space-separated string or an array of strings.

const vNodeTree = (
  <div className="outer">
    <SomeComponent className="inner one"/>
    <SomeComponent className="inner two"/>
  </div>
);
const renderedTree = render(vNodeTree, DOM);
const result1 = scryRenderedDOMElementsWithClass(renderedTree, 'inner');
const result2 = scryRenderedDOMElementsWithClass(renderedTree, 'inner one');
const result3 = scryRenderedDOMElementsWithClass(renderedTree, ['inner', 'two']);
const result4 = scryRenderedDOMElementsWithClass(renderedTree, 'three'); // Empty array

findRenderedDOMElementWithClass(renderedTree, classNames)

Returns a single DOM element with classNames. If more than one matches are found, throws an error.

classNames can be a space-separated string or an array of strings.

const vNodeTree = (
  <div className="outer">
    <SomeComponent className="inner one"/>
    <SomeComponent className="inner two"/>
  </div>
);
const renderedTree = render(vNodeTree, DOM);
const result1 = scryRenderedDOMElementsWithClass(renderedTree, 'outer');
const result2 = scryRenderedDOMElementsWithClass(renderedTree, 'inner one');
// Will throw an error because more than 1 matches were found...
const result3 = scryRenderedDOMElementsWithClass(renderedTree, 'inner');

scryRenderedDOMElementsWithTag(renderedTree, tagName)

Returns an array of DOM elements with tagName.

const vNodeTree = (
  <div>
    <h1>Heading</h1>
    <p>Paragraph One</p>
    <p>Paragraph Two</p>
    <p>Paragraph Three</p>
  </div>
);
const renderedTree = render(vNodeTree, DOM);
const result1 = scryRenderedDOMElementsWithTag(renderedTree, 'h1');
const result3 = scryRenderedDOMElementsWithTag(renderedTree, 'p');
const result4 = scryRenderedVNodesWithType(renderedTree, 'span'); // Empty array

findRenderedDOMElementWithTag(renderedTree, tagName)

Returns a single DOM element with tagName. If more than one matches are found, throws an error.

const vNodeTree = (
  <div>
    <h1>Heading</h1>
    <div>
      <p>Paragraph One</p>
      <p>Paragraph Two</p>
      <p>Paragraph Three</p>
    </div>
  </div>
);
const renderedTree = render(vNodeTree, DOM);
const result1 = findRenderedDOMElementWithTag(renderedTree, 'h1');
// Will throw an error because more than 1 matches were found...
const result2 = findRenderedDOMElementWithTag(renderedTree, 'p');

scryRenderedVNodesWithType(renderedTree, type)

Returns an array of rendered VNodes with type.

const vNodeTree = (
  <div>
    <h1>Heading</h1>
    <SomeComponent/>
    <SomeComponent/>
  </div>
);
const renderedTree = render(vNodeTree, DOM);
const result1 = scryRenderedVNodesWithType(renderedTree, 'h1');
const result2 = scryRenderedVNodesWithType(renderedTree, SomeComponent);
const result3 = scryRenderedVNodesWithType(renderedTree, 'p'); // Empty array

findRenderedVNodeWithType(renderedTree, type)

Returns a single rendered VNode with type. If more than one matches are found, throws an error.

const vNodeTree = (
  <div>
    <h1>Heading</h1>
    <p>Paragraph 1</p>
    <p>Paragraph 2</p>
    <SomeComponent/>
    <AnotherComponent/>
    <AnotherComponent/>
  </div>
);
const renderedTree = render(vNodeTree, DOM);
const result1 = findRenderedVNodeWithType(renderedTree, 'h1');
const result2 = findRenderedVNodeWithType(renderedTree, SomeComponent);
// Will throw an error because more than 1 matches were found...
const result3 = findRenderedVNodeWithType(renderedTree, 'p');
const result4 = findRenderedVNodeWithType(renderedTree, AnotherComponent);

scryVNodesWithType(vNodeTree, type)

Returns an array of VNode instances with type.

const vNodeTree = (
  <div>
    <h1>Heading</h1>
    <SomeComponent/>
    <SomeComponent/>
  </div>
);
const result1 = scryVNodesWithType(vNodeTree, 'h1');
const result2 = scryVNodesWithType(vNodeTree, SomeComponent);
const result3 = scryVNodesWithType(vNodeTree, 'p'); // Empty array

findVNodeWithType(vNodeTree, type)

Returns a single VNode instance with type. If more than one matches are found, throws an error.

const vNodeTree = (
  <div>
    <h1>Heading</h1>
    <SomeComponent/>
    <SomeComponent/>
  </div>
);
const result1 = findVNodeWithType(vNodeTree, 'h1');
// Will throw an error because more than 1 matches were found...
const result2 = findVNodeWithType(vNodeTree, SomeComponent);

isVNode(instance)

Returns true when instance is a VNode.

isVNodeOfType(instance, type)

Returns true when instance is a VNode of type.

isDOMVNode(instance)

Returns true when instance is a DOM-type VNode.

isDOMVNodeOfType(instance, type)

Returns true when instance is a DOM-type VNode of type.

isFunctionalVNode(instance)

Returns true when instance is a functional-type VNode.

isFunctionalVNodeOfType(instance, type)

Returns true when instance is a functional-type VNode of type.

isClassVNode(instance)

Returns true when instance is a class-type VNode.

isClassVNodeOfType(instance, type)

Returns true when instance is a class-type VNode of type.

isDOMElement(instance)

Returns true when instance is a DOM element.

isDOMElementOfType(instance, type)

Returns true when instance is a DOM element of type.

isRenderedClassComponent(instance)

Returns true when instance is a rendered class VNode.

isRenderedClassComponentOfType(instance, type)

Returns true when instance is a rendered class VNode of type.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
8.0.0-alpha.60next
4.0.0-alpha10alpha#4-1
3.9.0-alpha.1a5cdaaa0canary
1.0.0-beta90beta9
1.0.0-beta60beta6
1.0.0-beta430beta43
1.0.0-beta420beta42
1.0.0-beta410beta41
1.0.0-beta400beta40
1.0.0-beta370beta37
1.0.0-beta360beta36
8.2.352latest
1.0.0-beta441beta44

Version History

VersionDownloads (Last 7 Days)Published
5.6.35
8.2.352
8.2.20
8.2.10
8.2.00
8.1.10
8.1.00
8.0.61
8.0.531
8.0.40
8.0.30
8.0.20
8.0.10
8.0.00
8.0.0-alpha.60
8.0.0-alpha.50
8.0.0-alpha.40
8.0.0-alpha.30
7.4.11745
8.0.0-alpha.20
8.0.0-alpha.10
8.0.0-alpha.01
7.4.100
7.4.90
7.4.80
7.4.70
5.6.215
7.4.624
7.4.50
7.4.41
7.4.31
7.4.23
7.4.10
7.4.00
7.3.31
7.3.22
7.3.10
7.3.00
7.2.10
7.2.00
7.1.131
7.1.121
7.1.111
7.1.101
7.1.90
7.1.80
7.1.70
7.1.60
7.1.51
7.1.40
7.1.30
7.1.20
7.1.11
7.1.00
7.0.50
7.0.40
7.0.21
7.0.10
7.0.00
6.3.10
6.3.01
6.2.10
6.2.01
6.1.51
6.1.40
6.1.31
6.1.20
6.1.10
6.1.01
6.0.30
6.0.22
6.0.10
6.0.00
6.0.0-rc.53
6.0.0-rc.31
6.0.0-rc.10
6.0.0-rc.00
6.0.0-alpha.30
6.0.0-alpha.20
6.0.0-alpha.10
5.6.11
5.6.00
6.0.0-alpha.01
5.5.01
5.4.21
5.4.10
5.4.00
5.3.01
5.2.00
5.1.10
5.1.00
5.0.60
5.0.50
5.0.40
5.0.30
5.0.20
5.0.10
5.0.00
5.0.0-20
5.0.0-10
5.0.0-00
4.0.80
4.0.70
4.0.60
4.0.50
4.0.40
4.0.30
4.0.20
4.0.10
4.0.00
4.0.0-210
4.0.0-200
4.0.0-190
4.0.0-180
4.0.0-170
4.0.0-160
4.0.0-150
4.0.0-140
4.0.0-130
4.0.0-120
4.0.0-110
4.0.0-100
4.0.0-90
4.0.0-80
4.0.0-70
4.0.0-60
4.0.0-50
4.0.0-40
4.0.0-30
4.0.0-20
4.0.0-10
4.0.0-00
3.10.10
3.10.00
3.9.00
3.9.0-alpha.1a5cdaaa0
3.8.20
3.8.10
3.8.00
3.7.10
3.7.00
3.6.40
3.6.30
4.0.0-alpha1-alpha.d24e2d510
4.0.0-alpha10
3.6.10
3.6.00
3.5.40
3.5.30
3.5.20
3.5.10
3.5.00
3.4.40
3.4.30
3.4.20
3.4.0-alpha.73eb03ff0
3.4.00
3.3.1-alpha.ecaca8540
3.3.10
3.3.00
3.2.20
3.2.10
3.2.00
3.1.20
3.1.10
3.1.00
3.0.60
3.0.50
3.0.40
3.0.30
3.0.20
3.0.10
3.0.00
2.0.00
1.6.20
1.6.10
1.6.00
1.5.60
1.5.50
1.5.40
1.5.30
1.5.20
1.5.10
1.5.0-alpha.2f6639f80
1.5.0-alpha.949b4a8a0
1.4.2-alpha.9a8a49c60
1.4.20
1.4.2-alpha.5f5d59010
1.4.1-alpha.5f5d59010
1.4.10
1.4.1-alpha.927f437b0
1.4.1-alpha.5a4983fd0
1.4.00
1.3.10
1.3.00
1.3.0-rc.100
1.3.0-rc.90
1.3.0-rc.80
1.3.0-rc.70
1.3.0-rc.60
1.3.0-rc.50
1.3.0-rc.40
1.3.0-rc.30
1.3.0-rc.20
1.3.0-rc.10
1.3.0-rc.00
1.2.22
1.2.12
1.2.02
1.1.22
1.1.12
1.1.00
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.0-beta450
1.0.0-beta441
1.0.0-beta430
1.0.0-beta420
1.0.0-beta410
1.0.0-beta400
1.0.0-beta370
1.0.0-beta360
1.0.0-beta90
1.0.0-beta60
0.7.270
0.7.260
0.7.250
0.7.240
0.7.230
0.7.220
0.7.210
0.7.200
0.7.170
0.7.160
0.7.150
0.7.140
0.7.130
0.7.120
0.7.110
0.7.100
0.7.90
0.7.70
0.7.00
0.6.30
0.6.20
0.6.00
0.5.220
0.5.210
0.5.200

Package Sidebar

Install

npm i inferno-test-utils

Weekly Downloads

916

Version

8.2.3

License

MIT

Unpacked Size

80.4 kB

Total Files

14

Last publish

Collaborators

  • longlho
  • lukesheard
  • trueadm
  • havunen