Jasmine 2.0 rc* waits is not defined

六月ゝ 毕业季﹏ 提交于 2020-01-01 04:35:08

问题


Just upgraded to jasmine 2.0 rc5 from 1.3 and now all my tests that used waits() are broken because the waits() and waitsFor() function are undefined. I can't seem to find any reference to that anywhere online, is anyone aware of what is the new API to replace wait() ?


回答1:


Well, the usage syntax for asynchronous calls changed. You can easily see the differences between the two versions in its documentations:

Jasmine 1.3 Asynchronous support uses waitsFor() and run() functions.

According to Jasmine 2.0 Asynchronous support, these functions has been wiped out from the library. However, Jasmine 2.0 adds async support to the primitive beforeEach(), afterEach() and it() functions. The callback functions passed to these functions now can take an argument that indicates if the spec can or can't run.

Then, when you reach the necessary conditions to run your test (whenever your async job is complete), you simply call done(). And all the magic happens ;)

From the documentation:

describe("Asynchronous specs", function() {
    var value;

    beforeEach(function(done) {
        setTimeout(function() {
            value = 0;
            done();
        }, 1);
    });

    it("should support async execution of test preparation and expectations", function(done) {
        value++;
        expect(value).toBeGreaterThan(0);
        done();
    });
});

The it() spec above will run only after the setTimeout() call, because done() is called there. Note the it() callback takes an argument (done).




回答2:


Use jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000

Please refer the below URL for Jasmine Documentation... http://jasmine.github.io/2.0/introduction.html

Section is "Asynchronous Support" in the documentation.



来源:https://stackoverflow.com/questions/20119324/jasmine-2-0-rc-waits-is-not-defined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!