Skip to content

Commit

Permalink
Localized called in specs to prevent collision
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 27, 2009
1 parent e4e4f68 commit 5c993bf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 67 deletions.
1 change: 0 additions & 1 deletion lib/timers.js
Expand Up @@ -29,7 +29,6 @@
if (timers[i])
if ((timers[i].current += ms) - timers[i].last >= timers[i].step) {
var times = Math.floor((timers[i].current - timers[i].last) / timers[i].step)
print(i, times)
timers[i].last = timers[i].current
while (--times+1) timers[i]()
}
Expand Down
132 changes: 66 additions & 66 deletions spec/spec.core.js
@@ -1,75 +1,75 @@

describe 'Timers'
// describe 'setTimeout()'
// it 'should return unique ids'
// id = setTimeout(function(){}, 200)
// id2 = setTimeout(function(){}, 200)
// id3 = setTimeout(function(){}, 200)
// id2.should.eql id + 1
// id3.should.eql id2 + 1
// end
//
// it 'should not be called when ticked below the duration'
// called = false
// setTimeout(function(){ called = true }, 200)
// tick(100)
// called.should.be_false
// end
//
// it 'should be called when ticked passed the duration'
// called = false
// setTimeout(function(){ called = true }, 200)
// tick(200)
// called.should.be_true
// end
//
// it 'should be destroyed once called'
// called = false
// setTimeout(function(){ called = true }, 200)
// tick(200)
// called.should.be_true
// called = false
// tick(200)
// called.should.be_false
// end
// end
describe 'setTimeout()'
it 'should return unique ids'
id = setTimeout(function(){}, 200)
id2 = setTimeout(function(){}, 200)
id3 = setTimeout(function(){}, 200)
id2.should.eql id + 1
id3.should.eql id2 + 1
end

it 'should not be called when ticked below the duration'
var called = false
setTimeout(function(){ called = true }, 200)
tick(100)
called.should.be_false
end

it 'should be called when ticked passed the duration'
var called = false
setTimeout(function(){ called = true }, 200)
tick(200)
called.should.be_true
end

it 'should be destroyed once called'
var called = false
setTimeout(function(){ called = true }, 200)
tick(200)
called.should.be_true
called = false
tick(200)
called.should.be_false
end
end

describe 'setInterval()'
// it 'should return unique ids'
// id = setInterval(function(){}, 200)
// id2 = setInterval(function(){}, 200)
// id3 = setInterval(function(){}, 200)
// id2.should.eql id + 1
// id3.should.eql id2 + 1
// end
//
// it 'should be called when ticked passed the interval'
// called = false
// setInterval(function(){ called = true }, 200)
// tick(100)
// called.should.be_false
// tick(100)
// called.should.be_true
// called = false
// tick(100)
// called.should.be_false
// tick(200)
// called.should.be_true
// end
//
// it 'should be destroyed when id is passed to clearInterval()'
// called = false
// id = setInterval(function(){ called = true }, 200)
// tick(200)
// called.should.be_true
// called = false
// clearInterval(id)
// tick(400)
// called.should.be_false
// end
it 'should return unique ids'
id = setInterval(function(){}, 200)
id2 = setInterval(function(){}, 200)
id3 = setInterval(function(){}, 200)
id2.should.eql id + 1
id3.should.eql id2 + 1
end

it 'should be called when ticked passed the interval'
var called = false
setInterval(function(){ called = true }, 200)
tick(100)
called.should.be_false
tick(100)
called.should.be_true
called = false
tick(100)
called.should.be_false
tick(200)
called.should.be_true
end

it 'should be destroyed when id is passed to clearInterval()'
var called = false
id = setInterval(function(){ called = true }, 200)
tick(200)
called.should.be_true
called = false
clearInterval(id)
tick(400)
called.should.be_false
end

it 'should be called several times when a multiple of the interval is ticked'
called = 0
var called = 0
setInterval(function(){ ++called }, 200)
called.should.eql 0
tick(200)
Expand Down

0 comments on commit 5c993bf

Please sign in to comment.