@sterensoftware/hmx-testing
v0.2.1
Published
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`.
Downloads
14
Readme
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.