У меня есть компоненты React. Я хочу проверить их. Но я получаю непредвиденную ошибку при каждом попытке до findRenderedDOMComponentWithTag
с проверенным компонентом. Вот Карма журнал ошибок:reactjs get `undefined не является функцией` при тестировании с Jasmine
05 09 2015 20:31:23.450:INFO [watcher]: Changed file "/tmp/35ffb917aab483a567d1be6fed779291.browserify".
PhantomJS 2.0.0 (Linux 0.0.0) DestroySession should process user logout FAILED
TypeError: undefined is not a function (evaluating 'target.dispatchEvent(e)') in http://localhost:9876/karma.js (line 1134)
at /tmp/35ffb917aab483a567d1be6fed779291.browserify:59730:16
PhantomJS 2.0.0 (Linux 0.0.0): Executed 3 of 7 (1 FAILED) (skipped 4) (0.04 secs/0.019 secs)
Мой стек:
- CoffeeScript
- реагируют (+ JSX)
- browserify
- karma.js
- phantomjs
- жасмин
Компонент:
React = require('react')
ReactBootstrap = require('react-bootstrap')
Button = ReactBootstrap.Button
SessionActions = require('../../actions/session_actions.coffee')
module.exports = React.createClass
contextTypes: router: React.PropTypes.func
handleClick: (e) ->
e.preventDefault()
console.log 'хуйло'
SessionActions.destroy()
@context.router.transitionTo('/sessions/new')
render: ->
<Button onClick={@handleClick} className='btn btn-default navbar-btn'>Sign out</Button>
Тест:
React = require('react/react-with-addons.js')
TestUtils = React.addons.TestUtils
DestroySession = require('../../../../app/coffee/components/sessions/destroy.coffee')
describe 'DestroySession', ->
instance = undefined
beforeEach ->
instance = TestUtils.renderIntoDocument(<DestroySession />)
it 'should process user logout', ->
localStorage.setItem('token', 123)
localStorage.setItem('userName', 'Anonymous Person')
localStorage.setItem('userId', 11)
button = TestUtils.findRenderedDOMComponentWithTag(instance, 'button')
console.log button
Это очень странно, но я получаю сообщение об ошибке при попытке console.log
моей переменной кнопки. Если я прокомментирую последнюю строку моего теста, он будет передан. Что случилось?
Я вижу это так: я могу оценить и тест против экземпляра успешно, но если я нажимаю экземпляр 'console.log', я получаю то же самое точная ошибка. – XML