【发布时间】:2015-10-07 07:09:55
【问题描述】:
我在尝试使用 jest 框架测试我的 react js 代码时遇到了麻烦。
假设这是我的组件:
# coffee/global_widget.coffee
@GlobalWidget = React.createClass
render: ->
<div className='row'>
<div className='col-md-12'>
<TerminalWidget />
</div>
</div>
# coffee/terminal_widget.coffee
@TerminalWidget = React.createClass
render: ->
<div>Hey! This is the terminal!</div>
所以,我想使用jest 对其进行测试。
jest.dontMock '../coffee/global_widget'
describe 'GlobalWidget', ->
global.React = require('react/addons')
GlobalWidget = require('../coffee/global_widget')
TestUtils = React.addons.TestUtils
globalWidgetForTest = TestUtils.renderIntoDocument(<GlobalWidget />)
# body of the test
我有麻烦:
npm test
> terminal-ui@0.0.2 test /home/alex/my_project
> jest
Using Jest CLI v0.4.5
FAIL __tests__/global_widget-test.coffee (0.276s)
● GlobalWidget › it encountered a declaration exception
- ReferenceError: GlobalWidget is not defined
如果我将module.exports = @GlobalWidget 附加到coffee/global_widget.coffee,那么我得到TerminalWidget is not defined。 module.exports= 是什么?为什么我需要为代码中的每个组件都添加它们?
【问题讨论】:
标签: javascript coffeescript reactjs jestjs