Last active
August 19, 2019 00:44
-
-
Save tlcheah2/3cb7ca414acc3c8faaef2b35869870d3 to your computer and use it in GitHub Desktop.
Login Component Isolated Test
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
const loginServiceSpy = jasmine.createSpyObj('LoginService', ['login']); | |
describe('Login Component Isolated Test', () => { | |
let component: LoginComponent; | |
beforeEach(async(() => { | |
component = new LoginComponent(routerSpy, new FormBuilder(), loginServiceSpy); | |
})); | |
function updateForm(userEmail, userPassword) { | |
component.loginForm.controls['username'].setValue(userEmail); | |
component.loginForm.controls['password'].setValue(userPassword); | |
} | |
it('Component successfully created', () => { | |
expect(component).toBeTruthy(); | |
}); | |
it('component initial state', () => { | |
expect(component.submitted).toBeFalsy(); | |
expect(component.loginForm).toBeDefined(); | |
expect(component.loginForm.invalid).toBeTruthy(); | |
expect(component.authError).toBeFalsy(); | |
expect(component.authErrorMsg).toBeUndefined(); | |
}); | |
it('submitted should be true when onSubmit()', () => { | |
component.onSubmit(blankUser); | |
expect(component.submitted).toBeTruthy(); | |
expect(component.authError).toBeFalsy(); | |
}); | |
it('form value should update from when u change the input', (() => { | |
updateForm(validUser.username, validUser.password); | |
expect(component.loginForm.value).toEqual(validUser); | |
})); | |
it('Form invalid should be true when form is invalid', (() => { | |
updateForm(blankUser.username, blankUser.password); | |
expect(component.loginForm.invalid).toBeTruthy(); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment