mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 13:32:54 +08:00
feat(radio-button) fix thrown error on dismiss solves #6466
This commit is contained in:
@ -155,6 +155,8 @@ export class RadioButton {
|
||||
*/
|
||||
ngOnDestroy() {
|
||||
this._form.deregister(this);
|
||||
if (this._group) {
|
||||
this._group.remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,12 +86,32 @@ export function run() {
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('RadioButton', () => {
|
||||
|
||||
describe('ngOnDestroy', () => {
|
||||
it('should work without a group', () => {
|
||||
let rb1 = createRadioButton(false);
|
||||
expect(() => rb1.ngOnDestroy()).not.toThrowError();
|
||||
});
|
||||
|
||||
it('should remove button from group if part of a radio group', () => {
|
||||
let rb1 = createRadioButton();
|
||||
spyOn(rg, 'remove');
|
||||
rb1.ngOnDestroy();
|
||||
expect(rg.remove).toHaveBeenCalledWith(rb1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
let rg: RadioGroup;
|
||||
let form: Form;
|
||||
|
||||
function createRadioButton() {
|
||||
return new RadioButton(form, null, rg);
|
||||
function createRadioButton(shouldIncludeGroup = true) {
|
||||
return new RadioButton(form, null, shouldIncludeGroup? rg : null);
|
||||
}
|
||||
|
||||
function mockRenderer(): any {
|
||||
@ -110,6 +130,4 @@ export function run() {
|
||||
rg = new RadioGroup(mockRenderer(), mockElementRef());
|
||||
form = new Form();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user