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

Commit

Permalink
fix(componentRegistry): gracefully recover if no md-component-id is s…
Browse files Browse the repository at this point in the history
…pecified
  • Loading branch information
ThomasBurleson committed Dec 22, 2014
1 parent bb283f8 commit bf2266f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/components/sidenav/sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ function ComponentRegistry($log, $q) {
* @param handle the handle to identify the instance under.
*/
register: function(instance, handle) {
if ( !handle ) return angular.noop;

instance.$$mdHandle = handle;
instances.push(instance);

Expand Down
37 changes: 34 additions & 3 deletions src/components/sidenav/sidenav.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,50 @@ describe('mdSidenav', function() {
}));

it('should wait for next component registration', inject(function($mdComponentRegistry, $timeout) {
var resolved = undefined, count = 0;
var promise = $mdComponentRegistry.when('left');
var el = setup('md-component-id="left"');
var instance = $mdComponentRegistry.get('left');
var resolved = undefined;

promise.then(function(inst){ count += 1; });
$timeout.flush();

el.triggerHandler('$destroy');

el = setup('md-component-id="left"');
promise = $mdComponentRegistry.when('left');
promise.then(function(inst){ resolved = inst; });
promise.then(function(inst){
resolved = inst;
count += 1;
});

$timeout.flush();

expect(resolved).toBeDefined();
expect(count).toBe(2);

}));

it('should not find a component without an id', inject(function($mdComponentRegistry, $timeout) {
var el = setup();

var resolved = undefined, count = 0;
var promise = $mdComponentRegistry.when('left');
var instance = $mdComponentRegistry.get('left');

promise.then(function(inst){ resolved = inst; count += 1; });
$timeout.flush();

expect(count).toBe(0);
expect(instance).toBe(null);
expect(resolved).toBeUndefined();

}));

it('should properly destroy without a md-component-id', inject(function($mdComponentRegistry, $timeout) {
var el = setup();

el.triggerHandler('$destroy');

}));

});
Expand Down

0 comments on commit bf2266f

Please sign in to comment.