wurmlab / afra

Genome Annotation for the Masses
http://afra.sbcs.qmul.ac.uk
Apache License 2.0
36 stars 21 forks source link

Migrate older tests to Jasmine 2.0 #84

Closed hargup closed 7 years ago

hargup commented 9 years ago

Some of the js tests in the master fails with the error ReferenceError: waitsFor is not defined. That is because waitsFor 1 which provides Asynchronous support in Jasmine 1.3 is now replaced by an new syntax 2 Here are the list of the files that needs a fix. I got them from git grep "waitsFor"

yeban commented 9 years ago

You had a list of affected test files, right? can you update the issue with those?

hargup commented 9 years ago

You had a list of affected test files, right? can you update the issue with those?

Updated, btw this should be easy to fix.

yeban commented 9 years ago

Thanks. It's not necessarily as straightforward. From what I remember, I had found RemoteBinaryFile.spec.js to be a bit tricky.

proxy-m commented 1 year ago

I see, you delete several functions from Jasmine. But where to find them again? Test example is broken on SO: https://stackoverflow.com/questions/4662641/how-do-i-verify-jquery-ajax-events-with-jasmine/6199132#6199132

proxy-m commented 1 year ago

Is upgrade_to_2 guide is still actual?

https://jasmine.github.io/tutorials/upgrading_to_2

proxy-m commented 1 year ago

For some reason it can be rewrited to hard-readable code:

window.getProduct  = function getProduct (id, callback) {
    $.ajax({
        type: "GET",
        url: "data.json",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: callback,
    });
};

it("should make a real AJAX request", function (done) {
    spyOn(window, 'getProduct').and.callThrough(); //create a spy
    var callback = function() {
        expect(getProduct).toHaveBeenCalled(); //use the spy instead of callback
        done();
    };
    getProduct(123, callback);
});

P.S.: The old code was:

it("should make a real AJAX request", function () {
    var callback = jasmine.createSpy();
    getProduct(123, callback);
    waitsFor(function () {
        return callback.callCount > 0;
    });
    runs(function () {
        expect(callback).toHaveBeenCalled();
    });
});

function getProduct (id, callback) {
    $.ajax({
        type: "GET",
        url: "data.json",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: callback,
    });
}