-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No value accessor for form control when mocking MatSelectModule #157
Comments
For anyone who is experiencing the same issue, here is a workaround by stubbing manually // app.component.spec.ts
import { Component } from '@angular/core';
import {
ControlValueAccessor,
NG_VALUE_ACCESSOR,
ReactiveFormsModule,
} from '@angular/forms';
import { async, TestBed } from '@angular/core/testing';
import { MatOptionModule } from '@angular/material/core';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MockModule } from 'ng-mocks';
import { AppComponent } from './app.component';
@Component({
selector: 'mat-select',
template: '',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: MatSelectStubComponent,
multi: true,
},
],
})
class MatSelectStubComponent implements ControlValueAccessor {
writeValue(obj: any) {}
registerOnChange(fn: any) {}
registerOnTouched(fn: any) {}
setDisabledState(isDisabled: boolean) {}
}
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
MockModule(MatFormFieldModule),
MockModule(MatOptionModule),
],
declarations: [AppComponent, MatSelectStubComponent],
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
fixture.detectChanges();
expect(app).toBeTruthy();
});
}); |
Thank you for the report, I was able to reproduce the issue and working on the fix. |
Hi, might you verify that #160 works for you? |
Hi, I've pulled the fix and tried with it: it works 👍 |
chore(deps): update dependency @types/jest to v26.0.19
Hi all dear developers, This page is quite popular in search results. Might you create an issue in this repo and describe what you've been looking for? |
Sorry for a stupid question, but
Thank you. |
Hi,
When trying to mock the
mat-select
component from Angular Material 9, the following error appears:Error: No value accessor for form control with name: 'toppings'
.The error occurs only when calling
fixture.detectChanges()
in the test.Here is a repo with the minimal setup to reproduce this issue: https://github.com/volcomix/ng-mocks-mat-select-issue
Error details:
Thank you!
The text was updated successfully, but these errors were encountered: