【问题标题】:jasmine fixtures with iframe带有 iframe 的茉莉花灯具
【发布时间】:2015-03-04 11:44:17
【问题描述】:

我正在使用 jasmine 固定装置,并且我想使用其中包含 iframe 的 HTML 编写测试。

问题是测试在我的 iframe 加载之前执行。
图书馆本身有解决方案吗?
还是我必须实现自己的机制让它等待?

代码如下:

夹具:

<iframe id="test-iframe1" class="test-iframe1" src="data/tests/pages/iframe1.html" style="width: 400px; height: 600px;" frameborder="20"></iframe>

测试:

describe("iframe -", function() {

    beforeEach(function() {
        var f = jasmine.getFixtures();
        f.fixturesPath = 'base/tests/pages/';
        f.load('iframe-main.htm');
    });

    it('iframe exists', function() {
        // HERE - the iframe has not yet loaded
        expect($('#test-iframe1').length).toBe(1);
    });
});

【问题讨论】:

    标签: javascript iframe jasmine fixtures


    【解决方案1】:

    您需要在 beforeEach() 中添加 done() 函数,您将在其中检查 iframe 的加载

    JS

     beforeEach(function(done) {
        var f = jasmine.getFixtures();
        f.fixturesPath = 'base/tests/pages/';
        f.load('iframe-main.htm');
    
        $('#test-iframe1').load(function(){
            done();
        });
    
    });
    

    而且你的 it() 不会在 done() 调用之前运行。

    【讨论】:

      猜你喜欢
      • 2011-06-28
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多