使用jasmine-node和jquery-jasmine测试客户端JavaScript

时间:2013-01-02 18:21:43

标签: node.js testing bdd jasmine-jquery jasmine-node

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

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没有正确加载,但我不知道该怎么做。 (我对nodejsnpm的经验很少。)

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

我做错了什么?

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:1)

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

var $ = require("jasmine-jquery");
describe("A suite", function() { ...