javascript - 通过实习生对浏览器 CommonJS 模块进行单元测试

标签 javascript unit-testing intern

编写将使用 browserify 加载到浏览器中的模块。我尝试使用 dojo/node 插件对模块进行单元测试,但在尝试加载单元测试时它无法正常工作。我是否必须包装需要单元测试的模块(即在加载之前对它们进行浏览器化),或者是否有解决方法?

规范:

define([
    'intern!object',
    'intern/chai!assert',
    'require',
    // common css selectors
    'intern/dojo/node!app/selectors'
], function (
    registerSuite,
    assert,
    require,
    SEL
) {

    registerSuite({

        name: 'Selectors Unit test',

        'it is an object': function() {
            assert.ok(typeof SEL === 'object',
                      'Selectors is an object');
        }

    });

});

模块:

module.exports = {

    FOO : { _SELF: '#someId }

};

通过浏览器运行 http://localhost/node_modules/intern/client.html?config=tests/intern

给出的错误是未捕获错误:找不到 Node.js require

Dojo 插件可以在浏览器环境中工作吗?

最佳答案

不,dojo/node 无法在浏览器中工作。作为documentation指出,

dojo/node simply accesses the native require() function of node, passing the plugin argument as the parameter.

关于javascript - 通过实习生对浏览器 CommonJS 模块进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25555449/

相关文章:

javascript - 使用 JavaScript 从 HTML 元素中删除类

javascript - CSS Sprites 在页面的 HTML 中有效,但在 Javascript 中无效?

javascript - 复选框发送相同的值,无论是否选中 - javascript,html

selenium - 实习生 Leadfoot WaitForAddedById 功能?

java - 给定一个 bySelector 我怎样才能得到这个元素的 child 的选择器?

c# - 在 C# .NET 中测试静态类和方法

c# - 使用 Moq 来 stub 接口(interface)方法

matlab - Matlab 工具箱测试中的 stub

javascript - 在 Intern 中加载项目目录外的依赖项

angularjs - 将 intern 与 systemjs 一起使用