You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/automated/src/data/observable-tests.ts
+71-9Lines changed: 71 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -163,7 +163,7 @@ export var test_Observable_addEventListener_MultipleEvents = function () {
163
163
obj.addEventListener(events,callback);
164
164
obj.set('testName',1);
165
165
obj.test();
166
-
TKUnit.assert(receivedCount===2,'Callbacks not raised properly.');
166
+
TKUnit.assert(receivedCount===0,"Expected no event handlers to fire upon the 'propertyChange' event when listening for event name 'propertyChange,tested', as we have dropped support for listening to plural event names.");
TKUnit.assert(obj.hasListeners(Observable.propertyChangeEvent),'Observable.addEventListener for multiple events should trim each event name.');
180
-
TKUnit.assert(obj.hasListeners(TESTED_NAME),'Observable.addEventListener for multiple events should trim each event name.');
179
+
TKUnit.assert(obj.hasListeners(events),"Expected a listener to be present for event name 'propertyChange , tested', as we have dropped support for splitting plural event names.");
180
+
TKUnit.assert(!obj.hasListeners(Observable.propertyChangeEvent),"Expected no listeners to be present for event name 'propertyChange', as we have dropped support for splitting plural event names.");
181
+
TKUnit.assert(!obj.hasListeners(TESTED_NAME),"Expected no listeners to be present for event name 'tested', as we have dropped support for splitting plural event names.");
181
182
182
183
obj.set('testName',1);
183
184
obj.test();
184
185
185
-
TKUnit.assert(receivedCount===2,'Callbacks not raised properly.');
186
+
TKUnit.assert(receivedCount===0,"Expected no event handlers to fire upon the 'propertyChange' event when listening for event name 'propertyChange , tested', as we have dropped support for listening to plural event names (and trimming whitespace in event names).");
@@ -223,7 +224,7 @@ export var test_Observable_addEventListener_MultipleCallbacks_MultipleEvents = f
223
224
obj.set('testName',1);
224
225
obj.test();
225
226
226
-
TKUnit.assert(receivedCount===4,'The propertyChanged notification should be raised twice.');
227
+
TKUnit.assert(receivedCount===0,"Expected no event handlers to fire upon the 'propertyChange' event when listening for event name 'propertyChange , tested' with two different callbacks, as we have dropped support for listening to plural event names (and trimming whitespace in event names).");
// The identity of an event listener is determined by the tuple of
285
+
// [eventType, callback, thisArg], and influences addition and removal.
286
+
287
+
// If you try to add the same callback for a given event name twice, without
288
+
// distinguishing by its thisArg, the second addition will no-op.
289
+
obj.addEventListener(eventName,callback);
290
+
obj.addEventListener(eventName,callback);
291
+
obj.set('testName',1);
292
+
TKUnit.assert(receivedCount===1,'Expected Observable to fire exactly once upon a property change, having passed the same callback into addEventListener() twice');
293
+
obj.removeEventListener(eventName,callback);
294
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback) to remove all matching callbacks regardless of thisArg');
295
+
receivedCount=0;
296
+
297
+
// All truthy thisArgs are distinct, so we have three distinct identities here
298
+
// and they should all get added.
299
+
obj.addEventListener(eventName,callback);
300
+
obj.addEventListener(eventName,callback,1);
301
+
obj.addEventListener(eventName,callback,2);
302
+
obj.set('testName',2);
303
+
TKUnit.assert(receivedCount===3,'Expected Observable to fire exactly three times upon a property change, having passed the same callback into addEventListener() three times, with the latter two distinguished by each having a different truthy thisArg');
304
+
obj.removeEventListener(eventName,callback);
305
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback) to remove all matching callbacks regardless of thisArg');
306
+
receivedCount=0;
307
+
308
+
// If you specify thisArg when removing an event listener, it should remove
309
+
// just the event listener with the corresponding thisArg.
310
+
obj.addEventListener(eventName,callback,1);
311
+
obj.addEventListener(eventName,callback,2);
312
+
obj.set('testName',3);
313
+
TKUnit.assert(receivedCount===2,'Expected Observable to fire exactly three times upon a property change, having passed the same callback into addEventListener() three times, with the latter two distinguished by each having a different truthy thisArg');
314
+
obj.removeEventListener(eventName,callback,2);
315
+
TKUnit.assert(obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback, thisArg) to remove just the event listener that matched the callback and thisArg');
316
+
obj.removeEventListener(eventName,callback,1);
317
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback, thisArg) to remove the remaining event listener that matched the callback and thisArg');
318
+
receivedCount=0;
319
+
320
+
// All falsy thisArgs are treated alike, so these all have the same identity
TKUnit.assert(receivedCount===1,'Expected Observable to fire exactly once upon a property change, having passed the same callback into addEventListener() multiple times, each time with a different falsy (and therefore indistinct) thisArg');
330
+
obj.removeEventListener(eventName,callback);
331
+
TKUnit.assert(!obj.hasListeners(eventName),'Expected removeEventListener(eventName, callback) to remove all matching callbacks regardless of thisArg');
TKUnit.assert(obj.hasListeners(events),"Expected a listener to be present for event name 'propertyChange , tested', as we have dropped support for splitting plural event names.");
346
+
TKUnit.assert(!obj.hasListeners(Observable.propertyChangeEvent),"Expected no listeners to be present for event name 'propertyChange', as we have dropped support for splitting plural event names.");
347
+
TKUnit.assert(!obj.hasListeners(TESTED_NAME),"Expected no listeners to be present for event name 'tested', as we have dropped support for splitting plural event names.");
348
+
TKUnit.assert(receivedCount===0,"Expected no event handlers to fire upon the 'propertyChange' event when listening for event name 'propertyChange , tested', as we have dropped support for listening to plural event names (and trimming whitespace in event names).");
286
349
287
350
obj.set('testName',1);
288
351
obj.test();
289
352
290
353
obj.removeEventListener(events,callback);
291
354
292
-
TKUnit.assert(!obj.hasListeners(Observable.propertyChangeEvent),'Expected result for hasObservers is false');
293
-
TKUnit.assert(!obj.hasListeners(TESTED_NAME),'Expected result for hasObservers is false.');
355
+
TKUnit.assert(!obj.hasListeners(events),"Expected the listener for event name 'propertyChange , tested' to have been removed, as we have dropped support for splitting plural event names.");
294
356
295
357
obj.set('testName',2);
296
358
obj.test();
297
359
298
-
TKUnit.assert(receivedCount===2,'Expected receive count is 2');
360
+
TKUnit.assert(receivedCount===0,"Expected no event handlers to fire upon the 'propertyChange' event when listening for event name 'propertyChange , tested', as we have dropped support for listening to plural event names (and trimming whitespace in event names).");
0 commit comments