Код модульного теста не может прочитать содержимое компонента «jsx», результат теста всегда «Получено: 0»
Это снимок экрана с результатом модульного теста с использованием фермента и jest с реагированием. js
// ***************************** ********* компонент. js************************************ ************* //
class NetworkConfig extends Component {
constructor() {
super();
this.state = {
dataDeviceConfig: {
dhcp: false,
macAddress: '',
ipAddress: '',
subMask: '',
dns: '',
gateway: '',
},
alertMessage: "",
loader: false
};
}
render() {
return (
<div>
{console.log("Diagnostic Data", this.state.dataDeviceConfig)}
<Form onSubmit={this.handleSubmit}>
<div className="sn-forms-settings">
<FormItem
label={<IntlMessages id="settings.label.DHCP" />}
>
{getFieldDecorator('dhcp', {
})(
<Switch ............... />
)}
</FormItem>
<FormItem
label={(
<span>
<IntlMessages id="settings.label.MacAdres" />
</span>
)}
>
{getFieldDecorator('macAddress', {
initialValue: this.state.dataDeviceConfig.macAddress
})(
<label name="macAddress">{this.state.dataDeviceConfig.macAddress}</label>
)}
</FormItem>
</div>
</Form>
</div>
);
}
}
const mapStateToProps = ({ settingSense, common }) => {
const { dataDeviceConfig } = settingSense;
const {
loader,
alertMessage,
showAlert,
alertMessageStatus,
alertMessageComponent
} = common;
return {
dataDeviceConfig,
loader,
alertMessage,
showAlert,
alertMessageStatus,
alertMessageComponent
}
};
const NetworkConfigForm = Form.create()(NetworkConfig);
export default injectIntl(connect(mapStateToProps, {
getDevicEtherConfigAction, setDevicEtherConfigAction
, showLoaderAction, hideAlertAction, hideLoaderAction
})(NetworkConfigForm));
// ************************ ************** component.test. js***************************** ***************** //
import React from 'react';
import Enzyme,{shallow,configur } from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import configureMockStore from 'redux-mock-store';
import NetworkConfigForm from '../../../.....................';
import {Input} from "antd";
import {mountWithIntl,shallowWithIntl} from '../../helpers/intl-enzyme-test-helper.js';
Enzyme.configure({
adapter: new EnzymeAdapter(),
disableLifecycleMethods: false
});
describe('Network Config Test', () => {
it('render NetworkConfig Component', () => {
const state = {
settingSense:{
dataDeviceConfig: {
dhcp: false,
macAddress: '',
ipAddress: '',
subMask: '',
dns: '',
gateway: '',
}
},
common:{
loader: false,
alertMessage:'',
showAlert: false,
alertMessageStatus:'MESSAGE_SUCCESS',
alertMessageComponent:'ALERT_DEVICE_ETHER_CONFIG'
}
};
const mockStore = configureMockStore();
const store = mockStore(state);
const wrapper = shallowWithIntl(<NetworkConfigForm store={store}/>).dive();
expect(wrapper.find('.sn-forms-settings').children().length).toEqual(2)
});
});