Jasmine 2.0 rc *等待没有定义 [英] Jasmine 2.0 rc* waits is not defined

查看:128
本文介绍了Jasmine 2.0 rc *等待没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚从 1.3 升级到 jasmine 2.0 rc5 ,现在我使用等待()的所有测试都被破坏了因为等待() waitsFor()函数未定义。我似乎无法在网上任何地方找到任何引用,是否有人知道什么是替换wait()的新API?

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() ?

推荐答案

嗯,异步调用的使用语法发生了变化。
您可以在其文档中轻松查看两个版本之间的差异:

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

Jasmine 1.3异步支持使用 waitsFor() run() functions。

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

根据 Jasmine 2.0异步支持,这些功能已从库中消失。但是,Jasmine 2.0为原始 beforeEach() afterEach()添加了异步支持。 it()函数。传递给这些函数的回调函数现在可以使用一个参数来指示规范是否可以运行。

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.

然后,当你达到运行你的必要条件时测试(只要您的异步作业完成),您只需调用 done()。所有的魔法都发生了;)

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

来自文档:

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

上面的 it()规格将会运行只有在 setTimeout()调用之后,才会在那里调用 done()。注意 it()回调接受一个参数(已完成)。

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

这篇关于Jasmine 2.0 rc *等待没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆