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

useFakeTimers breaks test when used with native callbacks #66

Closed
ilgooz opened this issue Jun 7, 2016 · 7 comments
Closed

useFakeTimers breaks test when used with native callbacks #66

ilgooz opened this issue Jun 7, 2016 · 7 comments

Comments

@ilgooz
Copy link

ilgooz commented Jun 7, 2016

Test timeouts when I do have callbacks for native events in my code. removing fake timer from code makes it work again.

var test = require('tape');
var sinon = require('sinon');

test('1', (t) => {
  t.plan(1);

  var clock = sinon.useFakeTimers();

  var p = new webkitRTCPeerConnection({iceServers: []})
  p.createOffer(function(){ t.ok(true); }, function(){});
});

Chrome 50.0.2661 (Linux 0.0.0)

thank you

@ilgooz
Copy link
Author

ilgooz commented Jun 8, 2016

as I check this issue occur with tape. mocha works as expected. feel free to close the issue if you think there is nothing to do with lolex to solve this. I'll share my solution here if I find any.

@mantoni
Copy link
Member

mantoni commented Jun 8, 2016

I know that Mocha keeps a reference to setTimeout for it's own use, specifically to allow stubbing it in tests. Maybe tape doesn't do that and relies on setTimeout internally?

@ilgooz
Copy link
Author

ilgooz commented Jun 8, 2016

it is true. it depends(calls process.nextTick - which uses setTimeout to shim) only when doing async execution(xhr calls, browser native async operations, events that executed in async but not relevant with time). calling clock.tick(1) after assertion solves this problem(this where process.nextTick is called) but this is a quite ugly solution. the problem with test is, assertions works fine but tab output is never ended and this makes karma test to timeout.

following lines are relevant with this

@ilgooz
Copy link
Author

ilgooz commented Jun 8, 2016

I'll use lolex directly with createClock() and make my class accept a clock interface to not mess with global settings by using useFakeTimers(). this looks like the cleanest way to do it.
@mantoni about globals, my 2 cents on checking setTimeout's duration and do not stub it if it's equal to zero since zero value is always meant to be used to do job of nexTick. thanks!

@fatso83
Copy link
Contributor

fatso83 commented Jun 8, 2016

Closing this as this is a tape issue. Follow tape-testing/tape#292 for updates or file a PR there to see it fixed.

@fatso83
Copy link
Contributor

fatso83 commented Jun 10, 2016

@ilgooz : I filed an issue with tape and that is already fixed. Also filed on with through, so you might want to follow that one too: dominictarr/through#43. Or perhaps supply a fix if you really want to see it fixed ;-)

@ilgooz
Copy link
Author

ilgooz commented Jun 10, 2016

@fatso83 yes thanks. :')

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