检测 jasmine 测试何时完成
我正在运行这样的 jasmine 测试;
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
我想使用 JavaScript 检测测试何时完成。我该怎么办?
I am running jasmine tests like this;
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
I would like to detect, using JavaScript, when the tests complete. How can I?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如@Xv。建议添加一名记者即可。您可以做一些简单的事情:
请参阅 http://jasmine.github.io/2.2/custom_reporter。 html。
As @Xv. suggests, adding a reporter will work. You can do something as simple as:
See http://jasmine.github.io/2.2/custom_reporter.html.
一些替代方法:
A) 使用
ConsoleRunner
,接受onComplete
选项。旧版本 (1.2rc1) 收到完整的回调作为独立参数。由于您还提供了写入 (
options.print
) 的函数,因此您可以控制将测试报告写入控制台。您可以让多个报告器同时处于活动状态
jasmineEnv.addReporter()
。B) 还没有尝试过,但您可以创建自己的报告器,其中除了
jasmineDone()
C) 之外的每个公共方法都有空实现 检查作者保存的Jasmine google 群组中的旧帖子并覆盖 jasmine.getEnv().currentRunner().finishCallback:
Some alternative ways:
A) Use the
ConsoleRunner
, that accepts anonComplete
option. Older versions (1.2rc1) receive the complete callback as a standalone parameter.Since you also supply the function that writes (
options.print
) you keep control about having the test reports written to the console.You can have several reporters active at the same time
jasmineEnv.addReporter()
.B) Haven't tried, but you could create your own reporter, with empty implementations of every public method but
jasmineDone()
C) Check an old post in the Jasmine google group, where the author saves and overrides
jasmine.getEnv().currentRunner().finishCallback
:我找到了两种不同的方法来解决这个问题。一种是破解 jasmine 在完成时抛出自定义事件。因为我想在加载测试后进行屏幕抓取,所以我将事件触发器插入到“reportRunnerResults”末尾的 jasmine-html.js 中
然后这是监听事件的问题:
在我的例子中,我在 iFrame 中运行 jasmine并希望将结果传递到父窗口,因此我从第一个绑定触发父窗口中的一个事件:
也可以在没有 jquery 的情况下执行此操作。我的策略是轮询要添加到“完成时间”跨度的文本。在此示例中,我每 0.5 秒轮询一次,持续 8 秒。
I found two different ways to solve this issue. One is to hack jasmine to throw a custom event when it completes. Because I wanted to screen scrape after the test loaded, I inserted the event trigger into jasmine-html.js at the end of "reportRunnerResults"
Then it's a matter of listening for the event:
In my case, I was running jasmine in an iFrame and wanted to pass the results to a parent window, so I trigger an event in the parent from my first bind:
It is also possible to do this without jquery. My strategy was to poll for text to be added to the "finished-at" span. In this example I poll every .5 seconds for 8 seconds.
我正在使用 HtmlReporter 运行 Jasmine 1.3.1。我最终像这样挂钩:
I'm running Jasmine 1.3.1 with the HtmlReporter. I ended up hooking in like this: