В нашем приложении мы используем библиотеку jsoneditor. Наше приложение написано в реагировать, и мы реализовали jsoneditor аналогичным образом в качестве примера response_demo, который можно найти здесь
Нам нужно использовать реагирующую библиотеку для проверки следующего кода
// App.js
import React, { Component } from 'react';
import JSONEditorDemo from './JSONEditorDemo';
import './App.css';
class App extends Component {
state = {
json: {
'array': [1, 2, 3],
'boolean': true,
'null': null,
'number': 123,
'object': {'a': 'b', 'c': 'd'},
'string': 'Hello World'
}
};
render() {
return (
<div className="app">
<h1>JSONEditor React demo</h1>
<div className="contents">
<JSONEditorDemo
json={this.state.json}
onChangeJSON={this.onChangeJSON}
/>
<div className="code">
<pre>
<code>
{JSON.stringify(this.state.json, null, 2)}
);
}
onChangeJSON = (json) => {
this.setState ({json});
};
}
приложение по умолчанию для экспорта;
и
// JSONEditorDemo.js
import React, {Component} from 'react';
import JSONEditor from 'jsoneditor';
import 'jsoneditor/dist/jsoneditor.css';
import './JSONEditorDemo.css';
export default class JSONEditorDemo extends Component {
componentDidMount () {
const options = {
mode: 'tree',
onChangeJSON: this.props.onChangeJSON
};
this.jsoneditor = new JSONEditor(this.container, options);
this.jsoneditor.set(this.props.json);
}
componentWillUnmount () {
if (this.jsoneditor) {
this.jsoneditor.destroy();
}
}
componentWillUpdate(nextProps, nextState) {
this.jsoneditor.update(nextProps.json);
}
render() {
return (
<div className="jsoneditor-react-container" ref={elem => this.container = elem} />
);
}
}
Мы бы хотели охватить весь код в наших модульных тестах. Нам нужно проверить onChangeJSON в методе App.js и onChangeJSON в JSONEditorDemo
Как вы думаете, есть ли способ протестировать компоненты этого типа с помощью реагирующей-тестирующей библиотеки?