@@ -147,7 +147,7 @@ test('forcing execution', async t => {
147
147
} ) ;
148
148
149
149
test ( 'context check in debounced function' , async t => {
150
- await t . test ( 'should throw an error if debounced method is called with different contexts' , async ( ) => {
150
+ await t . test ( 'should throw an error if debounced method is called with different contexts of the same class ' , async ( ) => {
151
151
function MyClass ( ) { }
152
152
153
153
MyClass . prototype . debounced = debounce ( ( ) => { } ) ;
@@ -157,15 +157,32 @@ test('context check in debounced function', async t => {
157
157
158
158
instance1 . debounced ( ) ;
159
159
160
- let errorThrown = false ;
161
- try {
160
+ assert . throws ( ( ) => {
162
161
instance2 . debounced ( ) ;
163
- } catch ( error ) {
164
- errorThrown = true ;
165
- assert . strictEqual ( error . message , 'Debounced method called with different contexts.' , 'Error message should match' ) ;
166
- }
162
+ } , {
163
+ message : 'Debounced method called with different contexts of the same prototype.' ,
164
+ } , 'An error should have been thrown' ) ;
165
+ } ) ;
166
+
167
+ await t . test ( 'should not throw an error if debounced method is called with different contexts of different classes' , async ( ) => {
168
+ function MyClass1 ( ) { }
169
+ function MyClass2 ( ) { }
170
+
171
+ const debouncedFunction = debounce ( ( ) => { } ) ;
172
+
173
+ MyClass1 . prototype . debounced = debouncedFunction ;
174
+ MyClass2 . prototype . debounced = debouncedFunction ;
167
175
168
- assert . ok ( errorThrown , 'An error should have been thrown' ) ;
176
+ const instance1 = new MyClass1 ( ) ;
177
+ const instance2 = new MyClass2 ( ) ;
178
+
179
+ instance1 . debounced ( ) ;
180
+
181
+ assert . doesNotThrow ( ( ) => {
182
+ instance2 . debounced ( ) ;
183
+ } , {
184
+ message : 'Debounced method called with different contexts of the same prototype.' ,
185
+ } , 'An error should not have been thrown' ) ;
169
186
} ) ;
170
187
} ) ;
171
188
0 commit comments