【发布时间】:2015-06-29 00:08:27
【问题描述】:
我正在尝试运行此测试:
it("should not select anything (emptiness) by default", function() {
// given
//phantomjs.open("google.com"); // just guessing
// when
var text = wordHighlighter.getSelectedText();
// then
expect(text).toEqual(""); // nothing is selected (yet)
});
评论phantomjs.open("google.com") 测试通过。
我要测试的代码是:
var getSelectedText = function () {
var text = "";
if (window.getSelection) { // windows suppose to be open
text = window.getSelection().toString();
}
return text;
};
似乎我已经设置了我的 npm 依赖项。至少我的测试是从“grunt”命令开始的。
我的 package.json(例如)如下所示:
{
"name": "project-name",
"version": "0.0.1",
"devDependencies": {
"express": "~4.4.3",
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-karma": "~0.9.0",
"karma": "~0.12.28",
"karma-jasmine": "~0.3.2",
"karma-junit-reporter": "^0.2.2",
"karma-phantomjs-launcher": "~0.1.4",
"phantomjs": "~1.9.7-10",
"karma-ng-html2js-preprocessor" : "~0.1"
}
}
(我也有正确的Gruntfile.js和karma.conf.js)
更新:我最终得到一个错误(如果取消注释 phantomjs 行):
ReferenceError:找不到变量:phantomjs
(如果 phantomjs 来自我所依赖的 npm-packages,我不确定如何访问它)
如果我这样做:
var webPage = require('webpage');
var page = webPage.create();
page.open(...
然后:
ReferenceError:找不到变量:需要
我发现this 是可能的解决方案:但我确实使用jasmine 2.x
that 建议我拆分我的规格.. 仍然尝试弄清楚。
问:如何打开窗口(利用phantomjs)使测试与window'open/not undefined 一起工作?
【问题讨论】:
-
类似(未真正回答):stackoverflow.com/questions/11891998/…
标签: node.js gruntjs jasmine phantomjs karma-jasmine