diff --git a/addon/components/x-option.js b/addon/components/x-option.js index 4d9eb98..08daedf 100644 --- a/addon/components/x-option.js +++ b/addon/components/x-option.js @@ -70,6 +70,9 @@ export default Ember.Component.extend({ */ willDestroyElement: function() { this._super.apply(this, arguments); - this.get('select').unregisterOption(this); + let select = this.get('select'); + if(select) { + select.unregisterOption(this); + } } }); diff --git a/tests/unit/components/x-option-test.js b/tests/unit/components/x-option-test.js new file mode 100644 index 0000000..25e44be --- /dev/null +++ b/tests/unit/components/x-option-test.js @@ -0,0 +1,23 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { + describeComponent, + it +} from 'ember-mocha'; + + +describeComponent( + 'x-option', + 'XOptionComponent', + { + needs: [] + }, + function() { + it('does not blow up when destroyed before rendered', function() { + var component = this.subject(); + expect(function() { + component.willDestroyElement(); + }).not.to.throw(); + }); + } +);