摩卡柴等待莫代尔展示

时间:2016-06-02 23:27:21

标签: javascript jquery twitter-bootstrap mocha chai

我怎么能要求mocha / chai在预期测试完成之前等待模态显示?

我正在包装bootstrap模式并发出我自己的事件。 show工作正常,但我需要等待模式为shown才能进行下一次测试。我根本无法让done()工作。

describe("Modal", function() {
    describe("wrapModalEvents", function() {
        it("should wrap the show.bs.modal event", function() {
            var m = new Modal();
            m.wrapModalEvents();
            var res = {e:1};
            m.on('show', function(){
                res.e = 555;
            });
            m.modal();
            expect(res.e).to.equal(555);
        });
        it("should wrap the shown.bs.modal event", function() {
            var m = new Modal();
            m.wrapModalEvents();
            var res = {e:1};
            m.on('shown', function(){
                res.e = 123;
            });
            // need to wait at least one second
            expect(res.e).to.equal(123);
        });
    });
});

0 个答案:

没有答案