[英]Unit testing browser CommonJS modules via intern
Writing modules that will be loaded int the browser with browserify. 编写将通过browserify加载到浏览器中的模块。 I'm attempting to use the
dojo/node
plugin for unit testing the modules, but it doesn't work correctly when trying to load unit tests. 我正在尝试使用
dojo/node
插件对模块进行单元测试,但是在尝试加载单元测试时它无法正常工作。 Would I have to wrap modules that need unit testing (ie, browserify them before load), or is there a workaround? 我是否必须包装需要进行单元测试的模块(即在加载之前将其浏览器化),或者有解决方法?
Spec: 规格:
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: 模块:
module.exports = {
FOO : { _SELF: '#someId }
};
Running via browser at http://localhost/node_modules/intern/client.html?config=tests/intern
通过浏览器在
http://localhost/node_modules/intern/client.html?config=tests/intern
The error given is Uncaught Error: Cannot find the Node.js require
给出的错误是
Uncaught Error: Cannot find the Node.js require
Does the Dojo plugin work in a browser environment? Dojo插件可以在浏览器环境中工作吗?
No, dojo/node
will not work in a browser. 否,
dojo/node
在浏览器中不起作用。 As the documentation points out, 正如文档指出的那样,
dojo/node
simply accesses the nativerequire()
function of node, passing the plugin argument as the parameter.dojo/node
只是通过将plugin参数作为参数来访问dojo/node
的本机require()
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.