lundi 24 août 2015

Jasmine 2.0: how to use data from a single ajax call for all unit tests

I want to avoid running an ajax call before each test in Jasmine. Instead I would like to use data from single ajax call for all the tests, is there a way to do this?

Currently I am using beforeEach like this:

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
});

Aucun commentaire:

Enregistrer un commentaire