首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TestRunner不运行我的摩卡/柴区测试

TestRunner不运行我的摩卡/柴区测试
EN

Stack Overflow用户
提问于 2014-08-22 15:44:50
回答 1查看 518关注 0票数 0

尽管我尽了最大的努力,但当我在浏览器中运行testRunner.html页面时,我似乎无法让我的testRunner.html承认我的测试。我已经确认了,它输入了测试文件并在expect中运行,但是测试运行程序仍然说零通过,零失败。我还尝试将mocha.run()命令作为内联脚本移到testRunner.html页面中,但没有效果。

我配置错误的是什么?

testRunner.html

代码语言:javascript
复制
<!DOCTYPE html>
<html lang = "en">
    <head>
        <meta charset = "utf-8" />
        <title> Tests </title>
        <link href = "../node_modules/mocha/mocha.css" rel = "stylesheet">
    </head>
    <body>
        <div id="mocha"></div>
        <script src="../node_modules/mocha/mocha.js"></script>
        <script>
            mocha.setup('bdd');
        </script>
        <script src = "../node_modules/requirejs/require.js" data-main = "test.config.js"></script>
    </body>
</html>

test.config.js

代码语言:javascript
复制
require.config({
    baseUrl: '../src/public/js',
    paths: {
        jquery: '//code.jquery.com/jquery-2.1.1.min',
        chai: '/../../../node_modules/chai/chai',
        underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min',
        backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min',
        marionette: 'http://marionettejs.com/downloads/backbone.marionette',
        handlebars: '//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars',
        syphon: '//cdnjs.cloudflare.com/ajax/libs/backbone.syphon/0.4.1/backbone.syphon.min'
    },
    shim: {
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: ['jquery', 'underscore'],
            exports: 'Backbone'
        },
        marionette: {
            deps: ['backbone'],
            exports: 'Marionette'
        },
        syphon: {
            deps: ['backbone', 'marionette'],
            exports: 'Backbone.Syphon'
        },
        handlebars: {
            exports: 'Handlebars'
        }
    }
});

require([
    '../../../test/src/appTest'
], function() {
    if (typeof mochaPhantomJS !== "undefined") {
        mochaPhantomJS.run();
    }
    else {
        mocha.run();
    }
});

appTest.js

代码语言:javascript
复制
define(['chai'], function(chai) {
    describe('array', function() {
        chai.expect(1+1).to.equal(2);
    });
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-22 17:49:27

您需要将测试放在一个it调用中:

代码语言:javascript
复制
define(['chai'], function(chai) {
    describe('array', function() {
        it("1 + 1 = 2", function () {
            chai.expect(1+1).to.equal(2);
        });
    });
});

这完全是一个问题,你如何使用摩卡。在这里,RequireJS根本不是一个因素。

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

https://stackoverflow.com/questions/25450837

复制
相关文章

相似问题

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