Suite of utilities for testing Inferno applications
npm install inferno --save
npm install inferno-test-utils --save-dev
findAllInRenderedTree
findAllInVNodeTree
scryRenderedDOMElementsWithClass
findRenderedDOMElementWithClass
scryRenderedDOMElementsWithTag
findRenderedDOMElementWithTag
scryRenderedVNodesWithType
findRenderedVNodeWithType
scryVNodesWithType
findVNodeWithType
isVNode
isVNodeOfType
isDOMVNode
isDOMVNodeOfType
isFunctionalVNode
isFunctionalVNodeOfType
isClassVNode
isClassVNodeOfType
isDOMElement
isDOMElementOfType
isRenderedClassComponent
isRenderedClassComponentOfType
renderIntoContainer
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);
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);
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);
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
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');
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
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');
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
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);
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
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);
Returns true
when instance
is a VNode
.
Returns true
when instance
is a VNode
of type
.
Returns true
when instance
is a DOM-type VNode
.
Returns true
when instance
is a DOM-type VNode
of type
.
Returns true
when instance
is a functional-type VNode
.
Returns true
when instance
is a functional-type VNode
of type
.
Returns true
when instance
is a class-type VNode
.
Returns true
when instance
is a class-type VNode
of type
.
Returns true
when instance
is a DOM element.
Returns true
when instance
is a DOM element of type
.
Returns true
when instance
is a rendered class VNode
.
Returns true
when instance
is a rendered class VNode
of type
.