https://github.com/raxjs/enzyme-adapter-rax
Enzyme adapter for Rax
https://github.com/raxjs/enzyme-adapter-rax
enzyme rax
Last synced: 11 months ago
JSON representation
Enzyme adapter for Rax
- Host: GitHub
- URL: https://github.com/raxjs/enzyme-adapter-rax
- Owner: raxjs
- License: mit
- Created: 2020-04-29T13:37:47.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-19T02:48:36.000Z (about 6 years ago)
- Last Synced: 2025-06-22T17:08:18.768Z (12 months ago)
- Topics: enzyme, rax
- Language: JavaScript
- Homepage: https://github.com/alibaba/rax
- Size: 21.5 KB
- Stars: 2
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# enzyme-adapter-rax
This is an adapter to support using the [Enzyme](https://airbnb.io/enzyme/) UI
component testing library with [Rax](https://rax.js.org).
## Supported Rax version
The adapter supports Rax 1.x.
## Usage
Add the library to your development dependencies:
```sh
# If using npm
npm install --save-dev enzyme-adapter-rax
# If using yarn
yarn add --dev enzyme-adapter-rax
```
Then in the setup code for your tests, configure Enzyme to use the adapter
provided by this package:
```js
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-rax';
configure({ adapter: new Adapter() });
```
Once the adapter is configured, you can write Enzyme tests for your Rax
UI components following the [Enzyme docs](https://airbnb.io/enzyme/).
The full DOM rendering, shallow rendering and string rendering modes are
supported.
## Example projects
For runnable example projects, see the [examples/](examples/) directory. To run the
examples locally, clone this repository, then run:
```sh
cd examples/
npm install
npm test
```
## Differences compared to Enzyme + React
The general intent is that tests written using Enzyme + React can be easily made
to work with Enzyme + Rax. However there are some differences
in behavior between this adapter and Enzyme's React adapters to be aware of:
### Simulating events
The [simulate](https://airbnb.io/enzyme/docs/api/ReactWrapper/simulate.html)
API does not dispatch actual DOM events in the React adapters, it just calls
the corresponding handler. The Rax adapter does dispatch an actual event
using `element.dispatchEvent(...)`.
### Re-render
When target tested component is triggered rerender, you need use `jest.runAllTimers()` to resolve the async render.
**Example:**
```js
const wrapper = mount();
wrapper.find('button').simulate('click');
jest.runAllTimers();
expect(wrapper.text()).toEqual('Current value: 6');
```