Hoh*_*own 10 jasmine phantomjs
我想用Phantomjs和Jasmine进行单元测试javascript.Phantomjs的网站建议我使用单独的东西来处理这个问题,特别是PhantomJasmine.我下载了PhantomJasmine并运行了示例.一切都很顺利.然后我将该行添加var system = require('system');到example_spec.js的顶部.当我尝试运行示例时,Phantomjs现在抛出错误我得到"ReferenceError:找不到变量:require".所以,我想要做一些事情,比如启动浏览器,但看起来我无法结合jasmine和phantomjs语法.我只能使用Phantomjs运行纯茉莉.我怎样才能在同一个文件中使用它们?喜欢:
console.log('Loading a web page');
var page = new WebPage();
var url = "http://www.phantomjs.org/";
page.open(url, function (status) {
    //Page is loaded!
    describe("A suite", function() {
      it("contains spec with an expectation", function() {
        expect(true).toBe(true);
      });
    });
    phantom.exit();
});
这不完全是你应该如何使用它。控制 phantomjs 的代码不应与 jasmine 规范混淆,反之亦然。
您应该将规范分成 .js 文件,并使用 HTML 规范运行程序创建标准 jasmine 设置,该运行程序加载规范 .js 文件并在 phantomjs 中打开该 HTML 文件。
另一个解决方案是使用 grunt 与 phantomjs 和 jasmine 来自动运行 jasmine 规范。
https://github.com/cowboy/grunt 
https://github.com/creynders/grunt-jasmine-task
| 归档时间: | 
 | 
| 查看次数: | 9432 次 | 
| 最近记录: |