OpenAPITools / OpenAPITools/openapi-generator
Unable to test angular jasmine specs
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
We are using OpenAPI 3.0 for generating angular client. The client is generating as expected with api's and models to communicate with backend API app from Angular app. All is fine. But when we try to run angular jasmine specs with karma runner, we are getting issue like "Error: This constructor is not compatible with Angular Dependency Injection because its dependency at index 1 of the parameter list is invalid. This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator. Please check that 1) the type for the parameter at index 1 is correct and 2) the correct Angular decorators are defined for this class and its ancestors."
ts file
import { MemberProfileControllerService } from 'capstock-api/api/memberProfileController.service'; ### // Referring from Generated client from node_modules folder.
export class DashboardComponent implements OnInit {
constructor(private memberService: MemberProfileControllerService) {
this.memberService.handleFetchAll1().subscribe(data => {
const ELEMENT_DATA: MemberProfileDTO[] = data;
this.dataSource = new MatTableDataSource(ELEMENT_DATA);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
});
}
}
spec.ts file ### // Default file generated while creating component
let component: DashboardComponent;
let fixture: ComponentFixture;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DashboardComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
Any idea how to make the specs work?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated MemberProfileControllerService import and the DashboardComponent spec shown in the issue, then inspect how the Angular TestBed resolves that service during component creation. Reproduce the failure with the Karma/Jasmine test and determine what configuration is needed for the component spec to create successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100