0
を使用して反応させ、国際空港をのonChangeテストは、私は私の私の言語酵素
マイlocaleDropDown.js
import React from 'react'
import PropTypes from 'prop-types'
import Cookie from 'js-cookie'
const propTypes = {
locale: PropTypes.string.isRequired
}
class LocaleDropDown extends React.Component {
constructor() {
super()
this.state = {value: ''}
this.handleLocaleChange = this.handleLocaleChange.bind(this)
}
handleLocaleChange (e) {
Cookie.set('locale', e.target.value)
window.location.reload()
}
componentDidMount() {
this.setState({inputValue: Cookie.get('locale')})
}
render() {
return <div>
<select id="locale-value" onChange={this.handleLocaleChange} value={this.state.inputValue}>
<option value="en">English</option>
<option value="fr">French</option>
</select>
</div>
}
}
LocaleDropDown.propTypes = propTypes
export default LocaleDropDown
と私のテストは
const handleLocaleChange = sinon.spy();
const wrapper = shallow(<LocaleDropDown onChange = {handleLocaleChange}/>)
const selectInput = wrapper.find("#locale-value")
selectInput.node.value = 'en'
wrapper.find('select').simulate('change', selectInput);
expect(handleLocaleChange.called).toEqual(true)
あるを変更することができますアプリを反応におけるボタンコンポーネントのドロップダウンを持っています
しかし、それは私にエラーを与える LocaleDropDown>変更をシミュレートするときは、handleLocaleChangeを呼び出す必要があります
TypeError: Cannot add property value, object is not extensible
私は間違っていますか?
私はそれを行いました。私に同じエラーが出る – keerti
Reactが子どもたちに変更を加えるのを防ぎます。最初のロケールをpropsとして渡すか、 'selectInput.node.value = 'en''を削除する必要があります –