Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Chrome 67.0.3396 (Mac OS X 10.13.5) LoginComponent should call auth.login when passed a valid form with correct credentials onSubmit FAILED
- Expected spy login to have been called.
- at UserContext.<anonymous> src/app/components/login/login.component.spec.ts:87:26)
- at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke node_modules/zone.js/dist/zone.js:388:1)
- at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke node_modules/zone.js/dist/zone-testing.js:288:1)
- at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke node_modules/zone.js/dist/zone.js:387:1)
- onSubmit(form: NgForm) {
- if (form.valid) {
- this.authService.login(this.user.username, this.user.password)
- .subscribe(
- data => {
- console.log(data);
- /* TODO: Navigate to holding page etc */
- // Hide any error message that was previously shown
- this.hideErrorMsg = true;
- },
- err => {
- console.log(err);
- // Change error message to be shown
- this.errorMessage = 'Either username or password were incorrect';
- // Show the error message
- this.hideErrorMsg = false;
- }
- );
- }
- const validFormGoodCreds = <NgForm>{
- value: {
- password: "somePassword",
- username: "someUsername"
- }
- };
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- declarations: [LoginComponent],
- imports: [FormsModule, HttpClientModule]
- }).compileComponents();
- authLogoutSpy = spyOn(component['authService'], 'logout');
- it('should call auth.login when passed a valid form with correct credentials onSubmit', () => {
- component.onSubmit(validFormGoodCreds);
- expect(authLoginSpy).toHaveBeenCalled();
- // TODO: Check for navigation to holding page
- });
Add Comment
Please, Sign In to add comment