Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit bf2266f

Browse files
fix(componentRegistry): gracefully recover if no md-component-id is specified
1 parent bb283f8 commit bf2266f

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/components/sidenav/sidenav.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ function ComponentRegistry($log, $q) {
333333
* @param handle the handle to identify the instance under.
334334
*/
335335
register: function(instance, handle) {
336+
if ( !handle ) return angular.noop;
337+
336338
instance.$$mdHandle = handle;
337339
instances.push(instance);
338340

src/components/sidenav/sidenav.spec.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,50 @@ describe('mdSidenav', function() {
260260
}));
261261

262262
it('should wait for next component registration', inject(function($mdComponentRegistry, $timeout) {
263+
var resolved = undefined, count = 0;
263264
var promise = $mdComponentRegistry.when('left');
264265
var el = setup('md-component-id="left"');
265-
var instance = $mdComponentRegistry.get('left');
266-
var resolved = undefined;
266+
267+
promise.then(function(inst){ count += 1; });
268+
$timeout.flush();
267269

268270
el.triggerHandler('$destroy');
269271

272+
el = setup('md-component-id="left"');
270273
promise = $mdComponentRegistry.when('left');
271-
promise.then(function(inst){ resolved = inst; });
274+
promise.then(function(inst){
275+
resolved = inst;
276+
count += 1;
277+
});
272278

273279
$timeout.flush();
274280

281+
expect(resolved).toBeDefined();
282+
expect(count).toBe(2);
283+
284+
}));
285+
286+
it('should not find a component without an id', inject(function($mdComponentRegistry, $timeout) {
287+
var el = setup();
288+
289+
var resolved = undefined, count = 0;
290+
var promise = $mdComponentRegistry.when('left');
291+
var instance = $mdComponentRegistry.get('left');
292+
293+
promise.then(function(inst){ resolved = inst; count += 1; });
294+
$timeout.flush();
295+
296+
expect(count).toBe(0);
297+
expect(instance).toBe(null);
275298
expect(resolved).toBeUndefined();
299+
300+
}));
301+
302+
it('should properly destroy without a md-component-id', inject(function($mdComponentRegistry, $timeout) {
303+
var el = setup();
304+
305+
el.triggerHandler('$destroy');
306+
276307
}));
277308

278309
});

0 commit comments

Comments
 (0)