编写将使用 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 nativerequire()
function of node, passing the plugin argument as the parameter.
关于javascript - 通过实习生对浏览器 CommonJS 模块进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25555449/