Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upInput value is an empty string in Jasmine Tests using an combined element, attribute Component Selector #37646
Comments
|
Not sure if it's a bug or a feature (I'll let better specialists decide about that). But the typical way of testing a component that requires inputs is to actually pass inputs the way they're supposed to be passed, with a test such as this one:
|
This "workaround" works for me. Thanks! I think the main problem (I described) is that the component is created by the TestBed without any parent that gives the input into the component itself. So it could be a way to pass an argument object while creating the component fixture - e.g.: beforeEach(() => {
fixture = TestBed.createComponent(TestComponent, {
requiredInput: { anyKey: 'anyValue'}
});
component = fixture.componentInstance;
fixture.detectChanges();
});In this case each attribute represents a value the TestBed sets to the same named input of the component as a default value. |


Description
I've got a component with some inputs. Some of them are optional but the input
configis required to use the component. Therefore I defined a component selector that has an element part and an attribute part (e.g.app-my-component[config]). Now I always need to pass a config into the component if I want to use it. Great! I started the app withng serveand everything works fine. So far so good...While writing the component tests I'm coming in trouble. I set the config in the
beforeEachblock where the component fixture is also created. However the required input attributeconfigis always an empty string when I calledfixture.detectChanges().Here is the Test-File of the minimal Reproduction I wrote that shows exactly the behaviour.
Removing the attribute part of the selector solves the problem. But that is no way.
I've created a minimal GitHub repository with the reproduction of the issue. I used Angular 8 for the reproduction repository because my main project is still using Angular 8, too
Angular Version: