Created
January 11, 2022 16:00
-
-
Save muditlambda/9291561882069128486ec89496682f3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//login.component.spec.ts | |
import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
import { FormsModule } from '@angular/forms'; | |
import { By } from '@angular/platform-browser'; | |
import { Location } from "@angular/common"; | |
import { LoginComponent } from './login.component'; | |
describe('LoginComponent', () => { | |
let component: LoginComponent; | |
let fixture: ComponentFixture<LoginComponent>; | |
beforeEach(async () => { | |
await TestBed.configureTestingModule({ | |
imports: [FormsModule ], | |
declarations: [LoginComponent], | |
}).compileComponents(); | |
}); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(LoginComponent); | |
component = fixture.componentInstance; | |
fixture.detectChanges(); | |
}); | |
it('should create', () => { | |
expect(component).toBeTruthy(); | |
}); | |
it('should be able to login by entering email and password and submitting form', () => { | |
component.User['email'] = 'test@test.com'; | |
component.User['password'] = '123456789'; | |
const loginBtn = fixture.debugElement.query(By.css('button.login-btn')).nativeElement; | |
loginBtn.click(); | |
expect(component.submitted).toBeTrue; | |
}); | |
it('should route to register page by clicking “Sign Up here” link', () => { | |
const location: Location = TestBed.inject(Location); | |
const link =fixture.debugElement.query(By.css('a')).nativeElement; | |
link.click(); | |
expect(location.path()).toBe('/user-register'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment