Reputation: 695
having troubles with Unit tests. I've a new project that asking to help fix test , I am adding "CUSTOM_ELEMENTS_SCHEMA" so that angular does not go deeper in children component and I am getting this error below that I am not clear why.
Unexpected value 'custom-elements' imported by the module 'DynamicTestModule'
Componet Spec here
describe('CheckboxComponent', () => {
let component: CheckboxComponent;
let fixture: ComponentFixture<CheckboxComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [FormsModule, ReactiveFormsModule, CUSTOM_ELEMENTS_SCHEMA],
declarations: [ CheckboxComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CheckboxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Upvotes: 0
Views: 2331
Reputation: 685
You delete CUSTOM_ELEMENTS_SCHEMA from TestBed.configureTestingModule's imports. And add TestBed.configureTestingModule's schemas
TestBed.configureTestingModule(
imports: [FormsModule, ReactiveFormsModule],
declarations: [ CheckboxComponent ],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
.compileComponents();
}));
And if you import in CheckboxComponent class, import same module in TestBed.configureTestingModule.
And write "schemas: [CUSTOM_ELEMENTS_SCHEMA]" in CheckboxComponent.
Upvotes: 1
Reputation: 695
It's easy and simple
It's not import but 'schemas'
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
declarations: [ Component ]
})
.compileComponents();
Upvotes: 0