Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

Wraul opened this issue Jun 17, 2014 · 4 comments

Comments

@Wraul
Copy link

Wraul commented Jun 17, 2014

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
Copy link
Contributor

infews commented Jun 23, 2014

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
Copy link
Author

Wraul commented Jun 24, 2014

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
Copy link
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
Copy link
Author

Wraul commented Jul 25, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants