【发布时间】:2015-03-04 02:31:25
【问题描述】:
我有这样的 mocha.opts:
test/mocha/*.js
--recursive
--globals reactModulesToStub
--check-leaks
--compilers .:test/jsx-compiler.js
--reporter nyan
并且有两个测试在单独调用时通过,但使用递归选项失败。我错过了什么吗?
例如,如果我在这个单一的测试上运行 mocha,没有问题,但是在同一个目录中添加类似的测试会导致所有测试失败。
/** @jsx React.DOM */
//tests/app/loginstatus-test.js
var React = require('react/addons'),
assert = require('assert'),
sinon = require('sinon'),
stubs = (function(){
global.reactModulesToStub = [
'TestClass.js'
];
})(),
MyComponent = require('../../app/modules/LoginStatus.jsx'),
TestUtils = React.addons.TestUtils,
TestContext = require('./../lib/TestContext').getRouterComponent(MyComponent),
component = TestContext.component,
dom = TestContext.dom,
flux = TestContext.flux;
describe('LoginStatus', function() {
it('renders the LoginStatus class', function() {
TestUtils.findRenderedDOMComponentWithClass(
component, 'LoginStatus');
});
it('when mounted and clicked, should call AppActions.showPopupModal', function() {
sinon.spy(flux.actions.AppActions, "showPopupModal");
TestUtils.Simulate.click(component.refs.loginStatusText.getDOMNode());
assert(flux.actions.AppActions.showPopupModal.calledOnce);
});
});
【问题讨论】:
-
这两个测试是否都有像
global.reactModulesToStub这样的行?它们都在加载时运行,因此它们会发生冲突。 -
@loganfsmyth 谢谢,是的,它们都在加载时运行。这是我的解决方案github.com/adjavaherian/mocha-react