为什么我的实习测试失败了,“文档没有定义” [英] Why is my intern test failing with "document is not defined"
问题描述
sandbox / web / libs / ev / grids / FilterGrid.js
测试文件位于这里:
sandbox / web / libs / ev / tests / FilterGrid.js
我的实习配置文件位于这里:
sandbox / tests / intern.js
我的装载机和套件对象如下所示:
loader: {
package:[
{name:'dojo',location:'web / libs / dojo'},
{name:'dijit',location:'web / libs / dijit} ,
{name:'dgrid',location:'web / libs / dgrid'},
{name:'put-selector',location:'web / libs / put-selector'},
{name:'xstyle',location:'web / libs / xstyle'},
{name:'ev',location:'web / libs / ev'}
]
},
套件:['ev / tests / FilterGrid'],
当装载器尝试加载它时,我得到:
默认为控制台记者
ReferenceError:没有定义文件
在/home/bholm/Projects/src/sandbox/web/libs/dojo/selector/_loader.js:5:15
在execModule(/ home / bholm / Projects / src / sandbox / node_modules / intern / node_module
/dojo/dojo.js:512:54)
在/ home / bholm / Projects / src / sandbox / node_modules / intern / node_modules / dojo /dojo.js:579:7
at guardCheckComplete(/home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:563:4)
at checkComplete(/ home / bholm / Projects / src / sandbox / node_modules / intern / node_modules / dojo / dojo.js:571:27)
在onLoadCallback(/ home / bholm / Projects / src / sandbox / node_modules / intern / node_modules / dojo / dojo.js:653:7)
at /home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:746:5
at fs.js: 266:14
在Object.oncomplete(fs.js:107:15)
单元测试使用实习需要一个DOM文档定义?
我也注意到,实体列出了dojo2_core,因为它是依赖关系。所以它是使用未发行的代码?
任何帮助,将不胜感激!
看起来您正在尝试使用需要浏览器环境的Node.js客户端加载一些代码。这不行。您只应在浏览器中加载 ev / tests / FilterGrid
测试套件。你可以通过修改你的Intern配置文件看起来像这样:
define([ 'intern / node_modules / dojo / has'],function(has){
var suites = [];
if(has('host-browser')){
suites.push('ev / tests / FilterGrid');
}
返回{
// ...您现有的配置...
套件:套件,
// ...
};
});
I am new to Intern and struggling with trying to get a simple test to run in my environment. I was able to get the tutorial test to run but I've tried to set up a test where the test file is located inside my app directory hierarchy. The module being tested is located here:
sandbox/web/libs/ev/grids/FilterGrid.js
The test file is located here:
sandbox/web/libs/ev/tests/FilterGrid.js
My intern config file is located here:
sandbox/tests/intern.js
My loader and suites objects looks like this:
loader: {
packages: [
{ name: 'dojo', location: 'web/libs/dojo' },
{ name: 'dijit', location: 'web/libs/dijit },
{ name: 'dgrid', location: 'web/libs/dgrid' },
{ name: 'put-selector', location: 'web/libs/put-selector' },
{ name: 'xstyle', location: 'web/libs/xstyle' },
{ name: 'ev', location: 'web/libs/ev' }
]
},
suites: ['ev/tests/FilterGrid'],
When the loader tries to load this, I get:
Defaulting to "console" reporter
ReferenceError: document is not defined
at /home/bholm/Projects/src/sandbox/web/libs/dojo/selector/_loader.js:5:15
at execModule (/home/bholm/Projects/src/sandbox/node_modules/intern/node_module
/dojo/dojo.js:512:54)
at /home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:579:7
at guardCheckComplete (/home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:563:4)
at checkComplete (/home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:571:27)
at onLoadCallback (/home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:653:7)
at /home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:746:5
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
Does the unit tests using Intern need a DOM document defined?? I also notice that Intern lists dojo2_core as it's dependency. So it's using unreleased code?
Any help with this would be appreciated!
It looks like you’re trying to load some code using the Node.js client that requires a browser environment. This won’t work. You should only load the ev/tests/FilterGrid
test suite in a browser. You can do this by modifying your Intern configuration file to look something like this:
define([ 'intern/node_modules/dojo/has' ], function (has) {
var suites = [];
if (has('host-browser')) {
suites.push('ev/tests/FilterGrid');
}
return {
// ...your existing configuration...
suites: suites,
// ...
};
});
这篇关于为什么我的实习测试失败了,“文档没有定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!