Estou com um problema ao instanciar o SignUpComponent nos teste:
describe("SignUp Component", () => {
let component: SignupComponent;
let signupService: SignUpService;
let router: Router;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, VmessageModule, ReactiveFormsModule, RouterTestingModule.withRoutes([])],
providers: [SignUpService, UserNotTakenValidatorService],
declarations: [SignupComponent]
}).compileComponents();
}));
beforeEach(() => {
const fixture = TestBed.createComponent(SignupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
router = TestBed.get(Router);
signupService = TestBed.get(SignUpService);
});
it("SignUp Component should be instantiated", () => {
expect(component).toBeTruthy();
});
it("must register an user", () => {
const navigateSpy = spyOn(router, 'navigate');
spyOn(signupService, 'signup').and.returnValue(of(null));
component.signupForm.get('email').setValue('alvaro@alvaro.com');
component.signupForm.get('fullName').setValue('Alvaro');
component.signupForm.get('userName').setValue('alvaro');
component.signupForm.get('password').setValue('12345');
component.signup();
expect(navigateSpy).toHaveBeenCalledWith(['']);
});
});
Gerando este erro:
Chrome 89.0.4389.90 (Windows 10) SignUp Component SignUp Component should be instantiated FAILED
TypeError: Cannot read property 'nativeElement' of undefined
at SignupComponent.ngOnInit (src/app/home/signup/signup.component.ts:66:77)
at callHook (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:2486:1)
at callHooks (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:2456:1)
at executeInitAndCheckHooks (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:2408:1)
at refreshView (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:9194:1)
at renderComponentOrTemplate (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:9293:1)
at tickRootContext (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:10519:1)
at detectChangesInRootView (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:10544:1)
at RootViewRef.detectChanges (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:22549:1)
at ComponentFixture._tick (node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:141:1)