Skip to content

Commit

Permalink
fix: pingTimer test check correct timerId prop
Browse files Browse the repository at this point in the history
  • Loading branch information
olso-nordsec committed Mar 18, 2024
1 parent c62dc14 commit 8116828
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ npm test

This will run both `browser` and `node` tests.


### Running specific tests

For example, you can run `node -r esbuild-register --test test/pingTimer.ts`

### Browser

Browser tests use [`wtr`](https://modern-web.dev/docs/test-runner/overview/) as the test runner. To build browser bundle using [esbuild](https://esbuild.github.io/) and run browser tests, you can use the following command:
Expand Down
9 changes: 6 additions & 3 deletions test/pingTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('PingTimer', () => {
const cb = spy()
const pingTimer = new PingTimer(keepalive, cb, 'auto')

assert.ok(pingTimer['timer'], 'timer should be created automatically')
assert.ok(pingTimer['timerId'], 'timer should be created automatically')

clock.tick(keepalive * 1000 + 1)
assert.equal(
Expand All @@ -29,7 +29,10 @@ describe('PingTimer', () => {
clock.tick(keepalive * 1000 + 1)
assert.equal(cb.callCount, 2, 'should reschedule automatically')
pingTimer.clear()
assert.ok(!pingTimer['timer'], 'timer should not exists after clear()')
assert.ok(
!pingTimer['timerId'],
'timer should not exists after clear()',
)
})

it('should not re-schedule if timer has been cleared in check ping', () => {
Expand All @@ -52,6 +55,6 @@ describe('PingTimer', () => {
)
clock.tick(keepalive * 1000 + 1)
assert.equal(cb.callCount, 1, 'should not re-schedule')
assert.ok(!pingTimer['timer'], 'timer should not exists')
assert.ok(!pingTimer['timerId'], 'timer should not exists')
})
})

0 comments on commit 8116828

Please sign in to comment.