首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mocha.js --递归测试失败,但作为个人很好。

Mocha.js --递归测试失败,但作为个人很好。
EN

Stack Overflow用户
提问于 2015-03-04 02:31:25
回答 1查看 1.2K关注 0票数 0

我有这样的mocha.opts:

代码语言:javascript
复制
test/mocha/*.js
--recursive
--globals reactModulesToStub
--check-leaks
--compilers .:test/jsx-compiler.js
--reporter nyan

当单独调用时,有两个测试通过,但递归选项失败。我是不是遗漏了什么?

例如,如果我在这个单一测试上运行mocha,没有问题,但是在同一个目录中添加一个类似的测试会导致所有测试失败。

代码语言:javascript
复制
/** @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);
    });
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-10 22:20:45

这是一个名称空间问题。我没有意识到Mocha将所有的描述都包含在同一个名称空间中,如果您需要在测试之间使用干净的变量,那么将它们扩展到it();中--这是一个很好的例子,说明了我之前尝试做的事情。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28845707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档