Mocking the JavaScript Timeout Functions in IE 8 with Jasmine 2.0.0 #612

Closed
Wraul opened this Issue Jun 17, 2014 · 4 comments

Projects

None yet

3 participants

@Wraul

Hi
I can't get the following test to work in IE 8.

describe('Time mock in IE 8', function() {
    beforeEach(function() {
        jasmine.clock().install();
    });

    afterEach(function() {
        jasmine.clock().uninstall();
    });

    it('calls test after timeout', function() {
        var test = jasmine.createSpy('timeout');
        setTimeout(test, 1000);
        jasmine.clock().tick(1000);
        expect(test).toHaveBeenCalled();
    });
});

I checked what Sinon does and found this http://sinonjs.org/releases/sinon-ie-1.10.2.js
So I tested by adding this to my SpecHelper.js

var origSetTimeout = setTimeout;
function setTimeout() {}
setTimeout = origSetTimeout;

After that the spec runs correctly.

@infews

I wonder if this is a load order problem. We do test the clock in IE8 and it's passing. Can you share more of your environment?

@Wraul

I'm experimenting with running my specs using SpecRunner.html and Karma.

I have done some more testing based on your suggestion.
And there appears to be two separate issues.

SpecRunner.html
This is now working. I had included jQuery before Jasmine.
After moving the include to after Jasmine the test works in IE 8.
So that was my fault. Sorry about that.

Karma
This is still not working.
If setTimeout gets called before the first call to jasmine.clock().install() I get this problem in IE 8.

Exemplified like this

setTimeout(function() {}, 100);

describe('Clock', function() {
    beforeEach(function() {
        jasmine.clock().install();
    });

    afterEach(function() {
        jasmine.clock().uninstall();
    });

    it('works in IE 8', function() {
        var test = jasmine.createSpy('timeout');
        setTimeout(test, 1000);
        jasmine.clock().tick(1000);
        expect(test).toHaveBeenCalled();
    });
});

Without the first setTimeout call it works correctly.
Not sure if this is a problem with Jasmine or Karma.

@slackersoft
Jasmine member

From what you've said and my own testing, it looks like this isn't a problem in jasmine proper, but rather something that karma is doing. It it's working properly without karma, but breaks when karma is introduced, I would suggest opening an issue there.

Can we close this?

@Wraul

I agree. This is most likely an issue with Karma.
I have opened a ticket with Karma here
I'm closing this issue now.
Thank you.

@Wraul Wraul closed this Jul 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment