1

我的综合测试:

exports.testAssertObject = function(assert) {
    console.log(arguments);
    assert.ok(assert, "Assert object exists");
};

在 JPM 中失败TypeError: assert.ok is not a function

$jpm --version
0.0.29
$jpm test
JPM undefined Starting jpm test on Reuse Tab
Creating XPI
JPM undefined XPI created at ...\AppData\Local\Temp\jid1-K8e1vROHVMoXWQ@jetpack-0.6.1.xpi (327ms)
Created XPI at ...\AppData\Local\Temp\jid1-K8e1vROHVMoXWQ@jetpack-0.6.1.xpi
JPM undefined Creating a new profile
Running tests on Firefox 38.0a2/Gecko 38.0a2 ({ec8030f7-c20a-464f-9b0e-13a3a9e97384}) under winnt/x86.
console.log: reusetab: {"0":{"console":{},"passed":0,"failed":0,"testRunSummary":[],"expectFailNesting":0,"test":{"name":"./test/test-utils.testAssertObject","passed":0,"failed":0,"errors":{},"last":"START"},"isDone":false,"waitTimeout":null}}
console.error: reusetab: 
JPM undefined   Message: ReferenceError: assert is not defined
  Stack:
    exports.testAssertObject@resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid1-k8e1vrohvmoxwq-at-jetpack/test/test-utils.js:3:2
start@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/deprecated/unit-test.js:559:7
startMany/runNextTest/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/deprecated/unit-test.js:522:11
Handler.prototype.process@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:867:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:746:7
this.PromiseWalker.scheduleWalkerLoop/<@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:688:37



0 of 1 tests passed.
There were test failures...

我假设,与 cfx 不同, jpm 不会将assert 对象作为测试方法参数传递?

如何在异步测试中实现断言并通知“完成”

4

2 回答 2

2

JPM(如 cfx)默认情况下不使用 assert 方法运行测试,而是使用旧版本的测试工具来测试它们。使用当前测试工具所需要做的就是添加

require("sdk/test").run(exports);

到您的 trsts 文件,如您链接的单元测试页面上所述。

于 2015-04-07T15:00:18.797 回答
1

要获取更新的断言方法列表,请阅读

资源://gre/modules/commonjs/sdk/deprecated/unit-test.js

测试方法的第一个参数是在此资源中实现的 TestRuner 对象,并具有不同的接口:

尤其是:

  • ok()方法替换为assert()
  • throws()替换为assertRaises(func, predicate, message)(不同的签名)
  • equal()替换为assertEqual(),许多其他方法也以“assert”为前缀
  • done()方法现在也属于 TestRunner(您的测试方法没有第二个参数)以waitUntilDone(timeoutInMs)在 TestRunner 上声明您的方法异步调用
于 2015-04-04T15:58:17.207 回答