I am trying to test an Angular component with Cypress that uses the following imports and constructor dependencies:
Angular component:
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { environmentCommon } from "../../../environments/environment.common";
import { Router, ActivatedRoute } from "@angular/router";
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
import {FormBuilder, FormGroup, Validators, FormControl} from "@angular/forms";
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
[properties]
constructor(private router: Router,
private route: ActivatedRoute,
private formbuilder: FormBuilder,
private modalService: NgbModal) { }
[methods]
}
Cypress component spec file:
import {HeaderComponent} from "../../../src/app/components/header/header.component";
import {Router} from "@angular/router";
describe('Header component test', () => {
context('Testing the navigatiuon bar', () => {
it('Should have the top navigation bar with a bootstrap toolbox icon
and unordered list with tabs', () => {
cy.mount('<app-header></app-header>', {
declarations: [HeaderComponent],
providers:[ActivatedRoute, Router],
imports:[NgbModal, FormBuilder]
})
[More cypress commands]
}
Whenever I try to run the test in Cypress, however, I get the following error:
mount<app-header></app-header>, Object{3}
Error
Unexpected value 'NgbModal' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.
View stack trace