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

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

问题描述

刚刚从 1.3 升级到 jasmine 2.0 rc5,现在我所有使用 waits() 的测试都被破坏了,因为 waits()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() 函数.

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() 回调接受一个参数 (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).

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

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