【发布时间】:2015-10-05 20:10:53
【问题描述】:
我正在使用以下代码运行我的实习生测试
node node_modules/intern/runner.js config=tests/intern
在我的本地机器上。该应用程序正在使用 Dojo。 基本上我试图覆盖 window.alert 函数,因为我的一项测试由于意外警报而失败。
window.alert = function(msg) {
//override alert function
//...
}
我尝试将其放入我的实习生测试并得到错误。经过一番搜索,我了解到 window 对象在节点环境中不可用。我在哪里可以覆盖警报?
intern file 看起来像
define(['intern/lib/args'], function(args) {
var DEFAULT_PORT = "8080";
var urlInfo = {
PORT: args.port || DEFAULT_PORT,
BASE_URL : "http://localhost:".concat(args.port || DEFAULT_PORT, "/webtest"),
};
var config = {
proxyPort: 9000,
proxyUrl: 'http://localhost:9000',
capabilities: {
'selenium-version': '2.45.0',
},
...
...
};
return config;
});
实习生测试文件示例
define([
'intern!object',
'intern/chai!assert',
'intern/dojo/node!leadfoot/helpers/pollUntil',
'intern',
'intern/dojo/node!fs'
], function(registerSuite, assert, Pages, intern, fs) {
registerSuite ({
name: 'Tests',
setup: function() {
window.alert = function(msg){
console.log("Unexpected Alert: "+msg);
}
return this.remote.get(require.toUrl( intern.config.functionalInfo.BASE_URL)).maximizeWindow();
},
beforeEach: function() {
return
},
afterEach: function() {
return
},
'Test1' : function() {
this.timeout = 600000;
return this.remote
.setFindTimeout(5000)
....
},
}
【问题讨论】:
标签: javascript node.js dojo javascript-objects intern