1

我正在尝试使用jasmine-nodeand编写一些 JavaScript 单元测试jquery-jasmine,但遇到了配置问题。目前,这是我试图运行的唯一“测试”:

describe("A suite", function() {
    it("contains spec with an expectation", function() {
        loadFixtures('blah.html');
        expect(true).toBe(true);
    });
});

尝试运行测试时出现以下错误:

    Failures:

      1) A suite contains spec with an expectation
       Message:
         ReferenceError: loadFixtures is not defined
       Stacktrace:
         ReferenceError: loadFixtures is not defined
        at [object Object].<anonymous> (/home/chris/Source/www/projects/wash/spec/javascripts/blah.spec.js:6:9)
        at [object Object].execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
        at [object Object].next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
        at [object Object].start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
        at [object Object].execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
        at [object Object].next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
        at [object Object].start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
        at [object Object].execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2215:14)
        at [object Object].next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
        at [object Object].start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)

Finished in 0.006 seconds
1 test, 1 assertion, 1 failure

当我在测试中注释掉该loadFixtures行时,它工作正常。

我认为jasmine-jquery加载不正确,但我不确定该怎么做。nodejs(我对or的经验很少npm。)

如果它具有诊断价值,那么当我运行时which jasmine-node(在 bash 内)我会得到一个结果,但是当我运行时which jasmine-jquery,我不会。我认为这是因为前者是可执行的,而后者不是,但我不想做任何假设。(npm show表示两个软件包都已安装。)

我究竟做错了什么?

非常感谢您的帮助。

4

1 回答 1

2

您可能只需要在使用它之前要求它;-)

var $ = require("jasmine-jquery");
describe("A suite", function() { ...
于 2013-01-02T19:02:41.257 回答