Jasmine 2.0:如何使用单个ajax调用的数据进行所有单元测试

时间:2015-08-24 10:00:13

标签: javascript unit-testing jasmine

我想避免在Jasmine中的每个测试之前运行ajax调用。 相反,我想使用单个ajax调用的数据进行所有测试,有没有办法做到这一点?

目前我正在使用beforeEach,如下所示:

beforeEach(function(done) {
    $.ajax({
        url: '/vulnerability/data',
        success: function (response) {
            done();
        },
    dataType: 'html'
    });
});

it("test 1", function() {
    // ajax is called for the 1st time
    // this won't run until the done callback is invoked from the beforeEach
});

it("test 2", function() {
    // ajax is called for the 2nd time
    // this won't run until the done callback is invoked from the beforeEach
});

it("test N", function() {
    // ajax is called for the Nth time
    // this won't run until the done callback is invoked from the beforeEach
});

0 个答案:

没有答案