【问题标题】:Running a Jasmine test suite in Phantom.js without a server在没有服务器的情况下在 Phantom.js 中运行 Jasmine 测试套件
【发布时间】:2016-04-29 23:16:35
【问题描述】:

我正在尝试让 Phantom.js 运行一套用 Jasmine 编写的 JavaScript 测试。以下是重现我正在做的事情的步骤:

  • 获取最新版 Jasmine 框架的latest standalone release(压缩包)

  • 存档包含几个 javascript 文件的示例规范和可以在浏览器中运行这些规范的 SpecRunner.html 文件

  • 安装phantom.js并从phantom.js项目的example文件夹下载jasmine 2 runner

  • 尝试使用 phantom.js 运行 SpecRunner.html:

    phantomjs ./phantom/run-jasmine2.js ./jasmine/SpecRunner.html

(其中./phantom/run-jasmine2.js 是 phantom.js 的 jasmine2 runner 的路径,./jasmine/SpecRunner.html 是 jasmine 文件夹中带有示例规范的规范 runner 的路径)

我收到以下错误

TypeError: null is not an object (evaluating 'document.body.querySelector('.description').innerText')

Blocked a frame with origin "file://" from accessing a frame with origin "null".  The frame requesting access has a protocol of "file", the frame being accessed has a protocol of "about". Protocols must match.

因此,Phantom 似乎不高兴将规范运行程序直接作为磁盘中的文件提供给它,而不是作为由本地服务器提供的文件 (localhost:8080/SpecRunner.html)。您能否建议一种方法让 Phantom 使用规范运行程序文件而不启动服务器?如果可能的话,也不要使用 Karma。

【问题讨论】:

  • 你使用的是什么版本的 PhantomJS?

标签: javascript jasmine phantomjs


【解决方案1】:

这里有一个很好的例子,说明您可以使用 Karma, PhantomJS, Jasmine setup,更多关于 Karma 的文档可在 https://karma-runner.github.io 获得。

【讨论】:

    猜你喜欢
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 2016-06-22
    • 2012-03-19
    • 2023-01-09
    • 2020-04-21
    • 2010-12-06
    相关资源
    最近更新 更多