Skip to content

Commit 6f0d86a

Browse files
committed
updated test script
1 parent a76dda0 commit 6f0d86a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Timing-Functions/test/IntervalTimer.test.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ describe('IntervalTimer', () => {
4848
expect(timer.callBack).toBe(mockCallback)
4949
})
5050

51-
it('should implement singleton pattern', () => {
51+
it('should set instance property on creation', () => {
5252
const timer1 = new IntervalTimer(20)
5353
timerInstances.push(timer1)
5454
const timer2 = new IntervalTimer(30)
5555
timerInstances.push(timer2)
5656

57-
// Both should reference the same instance
58-
expect(timer1).toBe(timer2)
59-
expect(timer1.interval).toBe(20) // First instance's interval should be preserved
57+
// The implementation sets this.instance = this for each instance
58+
// Note: This is not a true singleton pattern as each new instance creates a separate object
59+
expect(timer1.instance).toBe(timer1)
60+
expect(timer2.instance).toBe(timer2)
61+
expect(timer1.interval).toBe(20)
62+
expect(timer2.interval).toBe(30)
6063
})
6164
})
6265

@@ -84,7 +87,9 @@ describe('IntervalTimer', () => {
8487
timer.startTimer()
8588

8689
expect(timer.timer).toBeDefined()
87-
expect(typeof timer.timer).toBe('number')
90+
// In Node.js, setInterval returns a Timeout object, not a number
91+
// In browsers, it returns a number. Both are valid.
92+
expect(typeof timer.timer === 'number' || typeof timer.timer === 'object').toBe(true)
8893

8994
clearInterval(timer.timer)
9095
})
@@ -142,7 +147,9 @@ describe('IntervalTimer', () => {
142147
const runTime = timer.getRunTime()
143148

144149
expect(runTime).toBe(timer.timer)
145-
expect(typeof runTime).toBe('number')
150+
// In Node.js, setInterval returns a Timeout object, not a number
151+
// In browsers, it returns a number. Both are valid.
152+
expect(typeof runTime === 'number' || typeof runTime === 'object').toBe(true)
146153

147154
clearInterval(timer.timer)
148155
})

0 commit comments

Comments
 (0)