jasmine-node done未定义

时间:2015-03-30 14:30:19

标签: javascript node.js jasmine-node

一直在尝试简单的异步测试。安装了jasmine-node npm install -g jasmine-node然后写了一个简单的模块并进行测试。

简单模块。

// weather.js
exports.get = function(city, callback) {
    callback(city);
};

和测试套件。

// weather-spec.js
var list = require("../modules/weather");

describe("Weather Forecast", function(data) {
    it('should get weather for London,UK', function() {
        list.get('London,UK', function(data) {
            expect(data).toEqual('London,UK');
            done();
        });
    });
});

我收到错误:

Stacktrace:
    ReferenceError: done is not defined

鉴于这个简单的例子,我无法看到我出错的地方。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:27)

done是传递给it的第一个参数:

it('should get weather for London,UK', function(done) {
    list.get('London,UK', function(data) {
        expect(data).toEqual('London,UK');
        done();
    });
});

答案 1 :(得分:1)

describe("Weather Forecast", function(data) {
    it('should get weather for London,UK', function(done) {
        list.get('London,UK', function(data) {
            expect(data).toEqual('London,UK');
            done();
        });
    });
});

确保您在done的回调中传递it