ku4es-react-testing

kodmunki™ Utilities for ECMAScript React Testing

Usage no npm install needed!

<script type="module">
  import ku4esReactTesting from 'https://cdn.skypack.dev/ku4es-react-testing';
</script>

README

Classes

Context

Functions

loadDom([markup], [config])

Loads a fully functional, unsecure, in-memory headless DOM. Note that you should only load this DOM if you know what you are loading into it, and what your test will be executing. This DOM can load external images and will run script. This does expose the ability for malicious code to potentially access your OS through Node.

loadSafeDom([markup], [config])

Load a secure in-memory headless DOM. Note that there are no security guarantees with this DOM, though it does not allow for image loading or running scripts, negating these avenues as potential attack vectors for malicious code.

unloadDom()

Unloads a DOM loaded with loadDom or loadSafeDom

renderComponent(component)function

Renders a component into a DOM loaded with loadDom or loadSafeDom

Context

Kind: global class

new Context(props)

Param
props

context.$render() ⇒ XML

Dependent classes can override this virtual $render method to create situations where they can do such things as updateChildProps on the fly to gain test coverage for such a scenario. To gain such coverage one can override this method and return the target component passing to it this.state. For example:

$render() { return <MyComponent { ...this.state }/> }

Kind: instance method of Context
Access: protected

context.updateChildProps(value)

This method exposes a entry point for a pattern that enables dependent tests to obtain test coverage for those cases where system components require testing of prop value updates during the course of their lifecycle. To leverage this pattern successfully the developer will need to extend this Context class and override the $render method such that it returns their target, prop-updating component after passing this.state into the target component. For example: return(<MyComponent {...this.state}/>)

Kind: instance method of Context
Access: public

Param Description
value Object literal of new props

context.rerender()

Exposes an expressive means to perform a rerendering of a this Context.

Kind: instance method of Context
Access: public

context.destroy()

Clean up this component and cover unmount

Kind: instance method of Context
Access: public

loadDom([markup], [config])

Loads a fully functional, unsecure, in-memory headless DOM. Note that you should only load this DOM if you know what you are loading into it, and what your test will be executing. This DOM can load external images and will run script. This does expose the ability for malicious code to potentially access your OS through Node.

Kind: global function

Param Type Description
[markup] string Optional initialization markup.
[config] Object JSDom configuration options.

loadSafeDom([markup], [config])

Load a secure in-memory headless DOM. Note that there are no security guarantees with this DOM, though it does not allow for image loading or running scripts, negating these avenues as potential attack vectors for malicious code.

Kind: global function

Param Type Description
[markup] string Optional initialization markup.
[config] Object JSDom configuration options.

unloadDom()

Unloads a DOM loaded with loadDom or loadSafeDom

Kind: global function

renderComponent(component) ⇒ function

Renders a component into a DOM loaded with loadDom or loadSafeDom

Kind: global function
Returns: function - - Function that returns a jQuery style selection result augmented with a local member component that returns a pointer to the rendered Component.

Param Type Description
component Component A React Component to test, e.g.