|
27 | 27 | const animationFrame = () => new Promise(requestAnimationFrame) |
28 | 28 |
|
29 | 29 | runTests(() => { |
30 | | - describe('My Counter Component', () => { |
| 30 | + describe('Basic Counter Component', () => { |
31 | 31 | it('should initialize with count from attribute', async () => { |
32 | 32 | const el = document.getElementById('test1') |
33 | 33 | const countSpan = el.querySelector('span') |
|
79 | 79 | const incrementBtn = el.querySelector('button') |
80 | 80 | const countSpan = el.querySelector('span') |
81 | 81 |
|
82 | | - el.count = 0 |
83 | | - await animationFrame() // Wait for scheduled effect execution |
84 | | - |
85 | 82 | // Click multiple times rapidly |
86 | 83 | incrementBtn.click() |
87 | 84 | incrementBtn.click() |
|
92 | 89 | assert.equal(countSpan.textContent, '3') |
93 | 90 | }) |
94 | 91 |
|
95 | | - it('should handle programmatic count updates', async () => { |
96 | | - const el = document.getElementById('test2') |
97 | | - const countSpan = el.querySelector('span') |
98 | | - |
99 | | - el.count = 100 |
100 | | - await animationFrame() // Wait for scheduled effect execution |
101 | | - |
102 | | - assert.equal(countSpan.textContent, '100') |
103 | | - |
104 | | - el.count = 101 |
105 | | - await animationFrame() // Wait for scheduled effect execution |
106 | | - |
107 | | - assert.equal(countSpan.textContent, '101') |
108 | | - }) |
109 | | - |
110 | | - it('should handle zero correctly', async () => { |
| 92 | + it('should not allow programmatic count updates', async () => { |
111 | 93 | const el = document.getElementById('test2') |
112 | 94 | const countSpan = el.querySelector('span') |
113 | | - |
114 | | - el.count = 0 |
115 | | - await animationFrame() |
116 | | - |
117 | | - assert.equal(countSpan.textContent, '0') |
| 95 | + assert.throws(() => { |
| 96 | + el.count = 100 |
| 97 | + }, TypeError) |
118 | 98 | }) |
119 | 99 |
|
120 | 100 | it('should maintain count across increment cycles', async () => { |
121 | 101 | const el = document.getElementById('test2') |
122 | 102 | const incrementBtn = el.querySelector('button') |
123 | 103 |
|
124 | | - el.count = 10 |
125 | | - await animationFrame() // Wait for initial state update |
126 | | - |
| 104 | + const initialCount = el.count |
127 | 105 | incrementBtn.click() |
128 | 106 | await animationFrame() // Wait for event handling and effect execution |
129 | | - assert.equal(el.count, 11) |
| 107 | + assert.equal(el.count, initialCount + 1) |
130 | 108 |
|
131 | 109 | incrementBtn.click() |
132 | 110 | await animationFrame() // Wait for event handling and effect execution |
133 | | - assert.equal(el.count, 12) |
| 111 | + assert.equal(el.count, initialCount + 2) |
134 | 112 | }) |
135 | 113 | }) |
136 | 114 | }) |
|
0 commit comments