Exception in unit tests with radio buttons: config.get is not a function

Hi,

I constantly get exceptions in my unit tests, if the component uses ion-radio:

ERROR: TypeError: config.get is not a function
TypeError: config.get is not a function
    at addEventListener (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/helpers-dd7e4b7b.js:49:1)
    at Radio.connectedCallback (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/ion-radio_2.entry.js:64:23)
    at safeCall (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-7a8b7a1c.js:1262:1)

The strange thing is, that these exceptions occur as soon as there is more than one test in a spec.ts file, but even if these tests are empty:

describe('SampleTest', () => {
    let component: MySampleComponent;
    let fixture: ComponentFixture<MySampleComponent>;

    beforeEach(async () => {
        TestBed.configureTestingModule({
            declarations: [MySampleComponent],
            schemas: [CUSTOM_ELEMENTS_SCHEMA],
            imports: [
                CommonModule,
                FormsModule,
                ReactiveFormsModule,
                RouterModule.forRoot([], { relativeLinkResolution: 'legacy' }),
                TranslateModule.forRoot({
                    activeLang: 'en'
                }),
                RouterTestingModule.withRoutes([]),
                IonicModule.forRoot()
            ]
        }).compileComponents().catch(error => fail(error));

        fixture = TestBed.createComponent(InAppPreferencesComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

    it('should run A', () => {
    });

    it('should run B', () => {
    });
});

If I remove the detectChanges, no error is thrown.

Any idea what’s going wrong here, or how to solve it?

Yup. I’m also seeing broken Karma testing with the same error message during testing that says

    ERROR: TypeError: config.get is not a function
TypeError: config.get is not a function
    at removeEventListener (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/helpers-dd7e4b7b.js:65:1)
    at SegmentButton.disconnectedCallback (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/ion-segment_2.entry.js:382:26)
    at safeCall (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-7a8b7a1c.js:1262:1)
    at disconnectedCallback (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-7a8b7a1c.js:1791:1)
    at http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-7a8b7a1c.js:1882:1
    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:400:1)
    at ProxyZoneSpec.push.93775.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-testing.js:301:1)
    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:399:1)
    at Zone.run (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:160:1)
    at NgZone.runOutsideAngular (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:28604:1), undefined

in the Karma logs.

I’m seeing the same issue in unit tests.

If anyone else was having this issue, it has been fixed some time ago and an update of the ionic (@ionic/angular) is needed. Please see: