Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasmine fixtures with iframe

I'm using jasmine fixtures and I want to write a test with an HTML that has an iframe in it.

The problem is that the test executes before my iframe loads.
Is there a solution for this in the library itself?
Or will I have to implement my own mechanism to make it wait?

Here's the code:

The fixture:

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

The test:

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);
    });
});
like image 501
Malki Avatar asked Dec 28 '25 18:12

Malki


1 Answers

You need to add done() function in beforeEach() where you will check loading of iframe

JS

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

    $('#test-iframe1').load(function(){
        done();
    });

});

And your it() will not run before done() invoke.

like image 91
Hennadii Shvedko Avatar answered Dec 31 '25 07:12

Hennadii Shvedko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!