opitzconsulting / uitest.js

uitest.js is able to load a webpage into a frame, instrument that page and the javascript in that page (e.g. add additional scripts at the end of the document, ...) and execute actions on that page.
MIT License
67 stars 8 forks source link

Setting and returning hash #8

Closed heiko-hardt closed 11 years ago

heiko-hardt commented 11 years ago

Hi Tobias,

the following code returns an 'empty string' as "win.location.hash" in FireFox. IE, Chrome, Safari, ... works well:

    it('should return the hash (#dummy.html)', function() {

        uit.url( relPath + "/index.html");
        uit.runs(function(window){
            win               = window;
            win.location.hash = 'dummy.html';
            expect(win.location.hash).toBe('#dummy.html');
        });

    });

I know this example seems to make no sense, but i run into the same problem if my app change the hash. FireFox only returns an initial hash.

Thanks in advance Heiko

tbosch commented 11 years ago

Hi, thanks for reporting. Yes, I can reproduce the problem. This seems to work, i.e. splitting the assignment and the checking of the hash in different uit.runs calls, by which uitest.js waits a little between them... I will investigate this further...

    it('should return the hash (#dummy.html)', function() {
        uit.runs(function(window){
            window.location.hash = 'dummy.html';
        });
        uit.runs(function(window){
            expect(window.location.hash).toBe('#dummy.html');
        });

    });
tbosch commented 11 years ago

Ah ha, somehow the iframe gets reloaded, i.e. the following test fails:

    it('should return the hash (#dummy.html)', function() {
        uit.runs(function(window){
            var win = window;
            win.location.hash = 'dummy.html';
            win.test = true;
        });
        uit.runs(function(window){
            expect(window.test).toBe(true);
            expect(window.location.hash).toBe('#dummy.html');
        });

    });
tbosch commented 11 years ago

Hi, thanks a lot for reporting this! I previously had an unreproducible problem with FF, and it turns out that it was the very same cause as your issue.

Reason behind this: We are rewriting the document using document.open/write/close. For IE, we need to do this inside of a timeout. However, doing this in a timeout results in the problem you mentioned in FF.

Tobias

heiko-hardt commented 11 years ago

Thanks for fixing ;-)