bahmutov / bahmutov/cypress-angular-unit-test
Unable to load HttpClient in Service of Component
- Dominant language
- TypeScript
- Stars
- 160
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
Let's suppose this structure:
```typescript
@Component({
selector: 'app-component',
templateUrl: './component.component.html',
styleUrls: ['./component.component.scss']
})
export class Component implements OnInit {
constructor(private service: CustomService) { }
ngOnInit(): void {
this.service.method().subscribe(...);
}
}
```
```typescript
@Injectable({
providedIn: 'root'
})
export class CustomService extends AbstractService {
private readonly URL: string;
constructor(private http: HttpClient) {
super('CustomService');
this.URL = this.getRelativeServiceURL('/suburl');
}
public method(): Observable {
return this.http.get(this.URL)
.pipe(map(value => {
return value.filtered;
}));
}
}
```
I wrote this test:
```typescript
it('should create', () => {
initEnv(Component, {
providers: [ CustomService ], imports: [ HttpClientTestingModule ]});
mount(Component);
cy.get(selector.empty.header)
.should('be.visible');
});
```
But I still get the error: "Can't resolve all parameters for CustomService: (?)."
Still not working when I import HttpClientModule, as you did in your Networking-Example
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the shown Cypress test and trace how initEnv registers providers and imports before mount(Component). Reproduce the CustomService dependency-injection error with HttpClientTestingModule, then verify that the component mounts and resolves HttpClient without the “Can't resolve all parameters” error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, cypress, typescript
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100