0
こんにちは、私は私はそれが正常に動作しますが、私はjsdomとコンポーネントのテストを書くしようとすると、それは私を示したのToDoアプリを作成したリアクト/ Reduxのは、テストに反応:不変違反:要素型が無効です:未定義
を学んでいます
import React from 'react'
import {addTodo} from '../actions'
import {connect} from 'react-redux'
let inputText
class AddTodo extends React.Component {
constructor(props, context){
super(props, context)
}
render(){
const {text, handleAdd} = this.props
return (
<div>
Text:
<input type='text' ref={node=>{ inputText=node}} /> <button onClick={()=>handleAdd(inputText.value)} >Add </button>
</div>
)
}
}
const handleAdd = (text)=>{
dispatch(addTodo(text))
}
const mapDispatchToProps = (dispatch, ownProps) =>{
return {
handleAdd: (text)=>{
dispatch(addTodo(text))
}
}
}
AddTodo = connect(null,mapDispatchToProps)(AddTodo)
export default AddTodo
spec.js
import React from 'react'
import ReactDOM from 'react-dom'
import {
renderIntoDocument,
scryRenderDOMComponentsWithTag,
Simulate
} from 'react-addons-test-utils'
import {AddTodo} from '../../src/containers/AddTodo'
import {expect} from 'chai'
describe('Add todo',()=>{
it('render the button and text field',()=>{
const component = renderIntoDocument(<AddTodo />);
const button = scryRenderDOMComponentsWithTag(component, 'button');
const input = scryRenderDOMComponentsWithTag(component, 'input');
expect(button.length).to.be(1);
expect(input.length).to.be(1);
})
})
(それだけでテキストフィールド+ボタンです)
コンポーネント:このエラーは、いくつかの時間を費やしたが、問題を考え出したことができませんでした
エラー:
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
OMG、私は怠慢です... – Kossel