Skip to content

Instantly share code, notes, and snippets.

@tlcheah2
Last active August 19, 2019 00:44
Show Gist options
  • Save tlcheah2/3cb7ca414acc3c8faaef2b35869870d3 to your computer and use it in GitHub Desktop.
Save tlcheah2/3cb7ca414acc3c8faaef2b35869870d3 to your computer and use it in GitHub Desktop.
Login Component Isolated Test
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