@sterensoftware/hmx-testing

0.2.0 • Public • Published

HMX Testing

HMX Testing supports React Component unit-testing by facilitating the mocking of the 3rd party dependencies: react, react/jsx-runtime, react/jsx-dev-runtime, and @sterensoftware/hmx.

It was designed and built to support true unit-testing of simple, declarative (logic-less) Components.


Installation

npm install -D @sterensoftware/hmx-testing

Usage

Mocking @sterensoftware/hmx

jest.mock('@sterensoftware/hmx', () => jest.requireActual('@sterensoftware/hmx-testing').hmx())

or

jest.mock('@sterensoftware/hmx', () => jest.requireActual('@sterensoftware/hmx-testing').hmx({ debug: true }))

Replaces HMX's WithState component function with a mock (jest.fn()) that returns an object with from and render.

Passing { debug: true } will result in output to the console.

Mocking react

jest.mock('react', () => jest.requireActual('@sterensoftware/hmx-testing').react())

or

jest.mock('react', () => jest.requireActual('@sterensoftware/hmx-testing').react({ debug: true }))

Use to mock React.createElement when testing with the "classic" runtime (or older versions of React). Will evaluate functional components and yield each element as an object with a tagName, props, and children.

Passing { debug: true } will result in output to the console.

Mocking react/jsx-runtime or react/jsx-dev-runtime

jest.mock('react/jsx-runtime', () => jest.requireActual('@sterensoftware/hmx-testing').jsx())

or

jest.mock('react/jsx-runtime', () => jest.requireActual('@sterensoftware/hmx-testing').jsx({ debug: true }))

or

jest.mock('react/jsx-dev-runtime', () => jest.requireActual('@sterensoftware/hmx-testing').jsx())

or

jest.mock('react/jsx-dev-runtime', () => jest.requireActual('@sterensoftware/hmx-testing').jsx({ debug: true }))

Use consistent with however you chose/choose to setup the "automatic" runtime to evaluate functional components and yield each element as an object with a tagName, props, and children.

Passing { debug: true } will result in output to the console.

Readme

Keywords

none

Package Sidebar

Install

npm i @sterensoftware/hmx-testing

Weekly Downloads

8

Version

0.2.0

License

MIT

Unpacked Size

4.56 kB

Total Files

3

Last publish

Collaborators

  • sterensoftwarellc