0

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

我有什么配置不正确?

testRunner.html

<!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

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

define(['chai'], function(chai) {
    describe('array', function() {
        chai.expect(1+1).to.equal(2);
    });
});
4

1 回答 1

2

您需要在it通话中进行测试:

define(['chai'], function(chai) {
    describe('array', function() {
        it("1 + 1 = 2", function () {
            chai.expect(1+1).to.equal(2);
        });
    });
});

这完全是您如何使用 Mocha 的问题。RequireJS 在这里根本不是一个因素。

于 2014-08-22T17:49:27.757 回答