【问题标题】:Mocha.js --recursive tests fail, but fine as individualsMocha.js --recursive 测试失败,但作为个人很好
【发布时间】: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

标签: reactjs mocha.js


【解决方案1】:

这是一个命名空间问题。我没有意识到 Mocha 将所有描述合并到同一个命名空间中,如果您需要在测试之间使用干净的变量,请将它们的范围限定为 it(); 这是一个很好的示例,说明如何做我之前尝试做的事情。

https://github.com/adjavaherian/mocha-react

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 2015-02-19
    相关资源
    最近更新 更多