firefox addon-sdk 单元测试

发布于 2024-12-01 03:03:00 字数 503 浏览 3 评论 0原文

有人使用过 addon-sdk(cfx 测试)中的单元测试吗?

我做了一个如下所示的测试:

exports.test_open_tab = function(test) {
   const tabs = require("tabs");
   tabs.open({
       url: "http://valid url with lots of params",
       onReady: function(tab) {
           test.done();
       }
   });

   test.waitUntilDone(600*1000);
};

基本上应该打开一个选项卡,等待 600 秒,然后将其标记为通过。

实际上在控制台中显示来自加载页面的许多错误和警告(jquery 和 google 分析内容,由加载页面使用),然后将测试标记为失败。

知道为什么吗?

Did anybody used the unit-tests from the addon-sdk(cfx test)?

I made a test that looks like this:

exports.test_open_tab = function(test) {
   const tabs = require("tabs");
   tabs.open({
       url: "http://valid url with lots of params",
       onReady: function(tab) {
           test.done();
       }
   });

   test.waitUntilDone(600*1000);
};

basically this should open a tab, wait 600seconds, and them mark it as passed.

It actually displays a lot of errors and warning in the console from the loaded page(jquery and google analytics stuff, used by the loaded page) and then it marks the test as failed.

Any idea why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2024-12-08 03:03:00

一个明显的问题是您实际上没有任何测试结果。如果调用 onReady() 的事实是一个肯定的结果,您应该这样写:

 onReady: function(tab) {
     test.pass("onReady called");
     test.done();
 }

顺便说一句,唯一会等待 600 秒的情况是如果未调用 onReady出于某种原因。否则,您的 test.done() 调用将完成测试执行。

您可以通过禁用 来减少记录的警告数量javascript.options.strict 首选项。然而,这些警告可能表明真正的问题,并且在当前的 Firefox 版本中,关闭控制台中 JavaScript 和 CSS 警告的显示可能更有意义。

One obvious issue is that you don't actually have any test results. If the fact that onReady() is called is a positive result you should write:

 onReady: function(tab) {
     test.pass("onReady called");
     test.done();
 }

Btw, the only case where it would wait 600 seconds is if onReady isn't called for some reason. Otherwise your test.done() call will complete the test execution.

You can somewhat reduce the number of warnings logged by disabling javascript.options.strict preference. However, these warnings might indicate real issues and in current Firefox versions it probably makes more sense to switch off display of JavaScript and CSS warnings in the console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文