茉莉花节点完成未定义

jasmine-node done is not defined

一直在尝试简单的异步测试。安装了 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

鉴于这个简单的例子,我看不出哪里错了。有人可以帮忙吗?

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

it('should get weather for London,UK', function(done) {
    list.get('London,UK', function(data) {
        expect(data).toEqual('London,UK');
        done();
    });
});
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();
        });
    });
});

确保在 it 的回调中传入 done