Jasmine/karma test case are not running in an orderly manner using Angular5












0















When running the test case using jasmine/karma test cases. I am facing n issue which is before starting with the Login spec test case the other spec files are all called before completing the Login. It need to happen in an orderly manner which is like



1.Login

2.Dashboard

3.Order

etc.



Is there a way to do this.



login.spec.ts file



import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule, Router } from '@angular/router';
import { LoginComponent } from './login.component';
import { DebugElement } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule, By } from '@angular/platform-browser';
import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
import { RouterTestingModule } from '@angular/router/testing';
import { APP_BASE_HREF } from '@angular/common';
import { LoginService } from './login.service';
import { HttpClientModule } from '@angular/common/http';
import { ApiService } from '../config/api.service';
import { ConfigService } from '../config/config.service';
import { Constants } from '../config/Constant';
import { SharedService } from '../shared/shared.service';
import { Http, BaseRequestOptions, ResponseOptions, Response, RequestMethod } from '@angular/http';
import { inject } from '@angular/core/testing';
import { MockBackend, MockConnection } from '@angular/http/testing';

describe('LoginComponent', () => {
let comp: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
let de: DebugElement;
let el: HTMLElement;
let userNameEl: DebugElement;
let passwordEl: DebugElement;
let submitEl: DebugElement;
let loginService: LoginService = null;
let backend: MockBackend = null;

TestBed.overrideComponent(LoginComponent, {
set: {
providers: [
{
provide: LoginService,
useValue: loginService
},
{
provide: Router,
useClass: class { navigate = jasmine.createSpy('navigate'); }
}
]
}
});


beforeEach(async(() => {
// loginService = loginService;
// backend = mockBackend;
TestBed.configureTestingModule({
declarations: [
LoginComponent
],
imports: [
RouterModule.forRoot([{
path: '',
component: LoginComponent
}]),
BrowserModule,
FormsModule,
ReactiveFormsModule,
Ng2Bs3ModalModule,
RouterTestingModule,
HttpClientModule
],
providers: [
MockBackend,
BaseRequestOptions,
{
provide: Http,
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backendInstance, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
LoginService,
ApiService,
ConfigService,
Constants,
SharedService,
{ provide: APP_BASE_HREF, useValue: '/' }
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(LoginComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('form'));
el = de.nativeElement;
userNameEl = fixture.debugElement.query(By.css('input[id=InputEmail1]'));
passwordEl = fixture.debugElement.query(By.css('input[id=InputPassword1]'));
submitEl = fixture.debugElement.query(By.css('.login-btn'));
});
}));

beforeEach(inject([LoginService, MockBackend], (Service: LoginService, mockBackend: MockBackend) => {
loginService = Service;
backend = mockBackend;
}));


it('should create', () => {
expect(comp).toBeTruthy();
});

it('To check the initial value', () => {
expect(comp.submitted).toBe(false);
expect(comp.spinnerlogo).toBeFalsy();
expect(comp.data).toEqual({});
});

it(`entering value in username and password input controls`, () => {
userNameEl.nativeElement.value = 'admin';
passwordEl.nativeElement.value = 'admin';
fixture.detectChanges();
});

it('after entering value the button should enabled and click Action should happen', () => {
expect(submitEl.nativeElement.disabled).toBeFalsy();
const loginButtonSpy = spyOn(comp, 'onSubmit');
submitEl.triggerEventHandler('click', null);
expect(loginButtonSpy).toHaveBeenCalled();
});

it('calling onSubmit method after clicked the login button', () => {
comp.submitted = true;
comp.spinnerlogo = true;
comp.errorDiagnostic = null;
comp.mailerrorDiagnostic = null;
expect(comp.submitted).toBeTruthy();
expect(comp.spinnerlogo).toBeTruthy();
expect(comp.errorDiagnostic).toBeNull();
expect(comp.mailerrorDiagnostic).toBeNull();
});

it('#login should call endpoint and return it's result', (done) => {
backend.connections.subscribe((connection: MockConnection) => {
const options = new ResponseOptions({
body: JSON.stringify({ success: true })
});
connection.mockRespond(new Response(options));

// Check the request method
expect(connection.request.method).toEqual(RequestMethod.Post);
// Check the url
expect(connection.request.url).toEqual('/auth/login');
// Check the body
// expect(connection.request.text())
expect(connection.request.text()).toEqual(JSON.stringify({ username: 'admin', password: 'admin' }));
// Check the request headers
expect(connection.request.headers.get('Content-Type')).toEqual('application/json');
});

loginService.login('admin', 'admin')
.subscribe((response) => {
console.log('response values are ---####------------ ', response);
// Check the response
expect(response.user.username).toEqual('admin');
expect(response.user.password).toEqual('admin');
// set value in sessionStorage
sessionStorage.setItem('currentUser', JSON.stringify(response));
sessionStorage.setItem('token', JSON.stringify(response.token));
sessionStorage.setItem('dismissOrders', 'false');

done();
},
(error) => {
expect(error).toThrowError();
});
});

});


the main problem is before executing the above file . The other spec file are executed



Thanks,
Kishan










share|improve this question

























  • Please post your code

    – auburg
    Nov 19 '18 at 12:41











  • I have posted the login component spec file. This login spec file should run and after that it should move to dashboard but before running the login the another component spec files are running.

    – Kishan Jr
    Nov 19 '18 at 13:08











  • Are you not mocking the login component in your other component spec files ? Your other spec files shouldn't need to do any login so you wouldn't have this problem of having to run things in a certain order (order shouldn't matter and you have no control over that anyway).

    – auburg
    Nov 19 '18 at 13:12











  • so basically you are saying if I need any login response for getting access token, I need to perform mocklogin in every spec file and set localstorage for it

    – Kishan Jr
    Nov 19 '18 at 13:17











  • Pretty much - you shouldn't be testing login in your other components. Presumably your other components have the loginservice injected as a constructor parameter so it can be mocked out.

    – auburg
    Nov 19 '18 at 13:20


















0















When running the test case using jasmine/karma test cases. I am facing n issue which is before starting with the Login spec test case the other spec files are all called before completing the Login. It need to happen in an orderly manner which is like



1.Login

2.Dashboard

3.Order

etc.



Is there a way to do this.



login.spec.ts file



import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule, Router } from '@angular/router';
import { LoginComponent } from './login.component';
import { DebugElement } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule, By } from '@angular/platform-browser';
import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
import { RouterTestingModule } from '@angular/router/testing';
import { APP_BASE_HREF } from '@angular/common';
import { LoginService } from './login.service';
import { HttpClientModule } from '@angular/common/http';
import { ApiService } from '../config/api.service';
import { ConfigService } from '../config/config.service';
import { Constants } from '../config/Constant';
import { SharedService } from '../shared/shared.service';
import { Http, BaseRequestOptions, ResponseOptions, Response, RequestMethod } from '@angular/http';
import { inject } from '@angular/core/testing';
import { MockBackend, MockConnection } from '@angular/http/testing';

describe('LoginComponent', () => {
let comp: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
let de: DebugElement;
let el: HTMLElement;
let userNameEl: DebugElement;
let passwordEl: DebugElement;
let submitEl: DebugElement;
let loginService: LoginService = null;
let backend: MockBackend = null;

TestBed.overrideComponent(LoginComponent, {
set: {
providers: [
{
provide: LoginService,
useValue: loginService
},
{
provide: Router,
useClass: class { navigate = jasmine.createSpy('navigate'); }
}
]
}
});


beforeEach(async(() => {
// loginService = loginService;
// backend = mockBackend;
TestBed.configureTestingModule({
declarations: [
LoginComponent
],
imports: [
RouterModule.forRoot([{
path: '',
component: LoginComponent
}]),
BrowserModule,
FormsModule,
ReactiveFormsModule,
Ng2Bs3ModalModule,
RouterTestingModule,
HttpClientModule
],
providers: [
MockBackend,
BaseRequestOptions,
{
provide: Http,
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backendInstance, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
LoginService,
ApiService,
ConfigService,
Constants,
SharedService,
{ provide: APP_BASE_HREF, useValue: '/' }
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(LoginComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('form'));
el = de.nativeElement;
userNameEl = fixture.debugElement.query(By.css('input[id=InputEmail1]'));
passwordEl = fixture.debugElement.query(By.css('input[id=InputPassword1]'));
submitEl = fixture.debugElement.query(By.css('.login-btn'));
});
}));

beforeEach(inject([LoginService, MockBackend], (Service: LoginService, mockBackend: MockBackend) => {
loginService = Service;
backend = mockBackend;
}));


it('should create', () => {
expect(comp).toBeTruthy();
});

it('To check the initial value', () => {
expect(comp.submitted).toBe(false);
expect(comp.spinnerlogo).toBeFalsy();
expect(comp.data).toEqual({});
});

it(`entering value in username and password input controls`, () => {
userNameEl.nativeElement.value = 'admin';
passwordEl.nativeElement.value = 'admin';
fixture.detectChanges();
});

it('after entering value the button should enabled and click Action should happen', () => {
expect(submitEl.nativeElement.disabled).toBeFalsy();
const loginButtonSpy = spyOn(comp, 'onSubmit');
submitEl.triggerEventHandler('click', null);
expect(loginButtonSpy).toHaveBeenCalled();
});

it('calling onSubmit method after clicked the login button', () => {
comp.submitted = true;
comp.spinnerlogo = true;
comp.errorDiagnostic = null;
comp.mailerrorDiagnostic = null;
expect(comp.submitted).toBeTruthy();
expect(comp.spinnerlogo).toBeTruthy();
expect(comp.errorDiagnostic).toBeNull();
expect(comp.mailerrorDiagnostic).toBeNull();
});

it('#login should call endpoint and return it's result', (done) => {
backend.connections.subscribe((connection: MockConnection) => {
const options = new ResponseOptions({
body: JSON.stringify({ success: true })
});
connection.mockRespond(new Response(options));

// Check the request method
expect(connection.request.method).toEqual(RequestMethod.Post);
// Check the url
expect(connection.request.url).toEqual('/auth/login');
// Check the body
// expect(connection.request.text())
expect(connection.request.text()).toEqual(JSON.stringify({ username: 'admin', password: 'admin' }));
// Check the request headers
expect(connection.request.headers.get('Content-Type')).toEqual('application/json');
});

loginService.login('admin', 'admin')
.subscribe((response) => {
console.log('response values are ---####------------ ', response);
// Check the response
expect(response.user.username).toEqual('admin');
expect(response.user.password).toEqual('admin');
// set value in sessionStorage
sessionStorage.setItem('currentUser', JSON.stringify(response));
sessionStorage.setItem('token', JSON.stringify(response.token));
sessionStorage.setItem('dismissOrders', 'false');

done();
},
(error) => {
expect(error).toThrowError();
});
});

});


the main problem is before executing the above file . The other spec file are executed



Thanks,
Kishan










share|improve this question

























  • Please post your code

    – auburg
    Nov 19 '18 at 12:41











  • I have posted the login component spec file. This login spec file should run and after that it should move to dashboard but before running the login the another component spec files are running.

    – Kishan Jr
    Nov 19 '18 at 13:08











  • Are you not mocking the login component in your other component spec files ? Your other spec files shouldn't need to do any login so you wouldn't have this problem of having to run things in a certain order (order shouldn't matter and you have no control over that anyway).

    – auburg
    Nov 19 '18 at 13:12











  • so basically you are saying if I need any login response for getting access token, I need to perform mocklogin in every spec file and set localstorage for it

    – Kishan Jr
    Nov 19 '18 at 13:17











  • Pretty much - you shouldn't be testing login in your other components. Presumably your other components have the loginservice injected as a constructor parameter so it can be mocked out.

    – auburg
    Nov 19 '18 at 13:20
















0












0








0








When running the test case using jasmine/karma test cases. I am facing n issue which is before starting with the Login spec test case the other spec files are all called before completing the Login. It need to happen in an orderly manner which is like



1.Login

2.Dashboard

3.Order

etc.



Is there a way to do this.



login.spec.ts file



import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule, Router } from '@angular/router';
import { LoginComponent } from './login.component';
import { DebugElement } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule, By } from '@angular/platform-browser';
import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
import { RouterTestingModule } from '@angular/router/testing';
import { APP_BASE_HREF } from '@angular/common';
import { LoginService } from './login.service';
import { HttpClientModule } from '@angular/common/http';
import { ApiService } from '../config/api.service';
import { ConfigService } from '../config/config.service';
import { Constants } from '../config/Constant';
import { SharedService } from '../shared/shared.service';
import { Http, BaseRequestOptions, ResponseOptions, Response, RequestMethod } from '@angular/http';
import { inject } from '@angular/core/testing';
import { MockBackend, MockConnection } from '@angular/http/testing';

describe('LoginComponent', () => {
let comp: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
let de: DebugElement;
let el: HTMLElement;
let userNameEl: DebugElement;
let passwordEl: DebugElement;
let submitEl: DebugElement;
let loginService: LoginService = null;
let backend: MockBackend = null;

TestBed.overrideComponent(LoginComponent, {
set: {
providers: [
{
provide: LoginService,
useValue: loginService
},
{
provide: Router,
useClass: class { navigate = jasmine.createSpy('navigate'); }
}
]
}
});


beforeEach(async(() => {
// loginService = loginService;
// backend = mockBackend;
TestBed.configureTestingModule({
declarations: [
LoginComponent
],
imports: [
RouterModule.forRoot([{
path: '',
component: LoginComponent
}]),
BrowserModule,
FormsModule,
ReactiveFormsModule,
Ng2Bs3ModalModule,
RouterTestingModule,
HttpClientModule
],
providers: [
MockBackend,
BaseRequestOptions,
{
provide: Http,
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backendInstance, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
LoginService,
ApiService,
ConfigService,
Constants,
SharedService,
{ provide: APP_BASE_HREF, useValue: '/' }
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(LoginComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('form'));
el = de.nativeElement;
userNameEl = fixture.debugElement.query(By.css('input[id=InputEmail1]'));
passwordEl = fixture.debugElement.query(By.css('input[id=InputPassword1]'));
submitEl = fixture.debugElement.query(By.css('.login-btn'));
});
}));

beforeEach(inject([LoginService, MockBackend], (Service: LoginService, mockBackend: MockBackend) => {
loginService = Service;
backend = mockBackend;
}));


it('should create', () => {
expect(comp).toBeTruthy();
});

it('To check the initial value', () => {
expect(comp.submitted).toBe(false);
expect(comp.spinnerlogo).toBeFalsy();
expect(comp.data).toEqual({});
});

it(`entering value in username and password input controls`, () => {
userNameEl.nativeElement.value = 'admin';
passwordEl.nativeElement.value = 'admin';
fixture.detectChanges();
});

it('after entering value the button should enabled and click Action should happen', () => {
expect(submitEl.nativeElement.disabled).toBeFalsy();
const loginButtonSpy = spyOn(comp, 'onSubmit');
submitEl.triggerEventHandler('click', null);
expect(loginButtonSpy).toHaveBeenCalled();
});

it('calling onSubmit method after clicked the login button', () => {
comp.submitted = true;
comp.spinnerlogo = true;
comp.errorDiagnostic = null;
comp.mailerrorDiagnostic = null;
expect(comp.submitted).toBeTruthy();
expect(comp.spinnerlogo).toBeTruthy();
expect(comp.errorDiagnostic).toBeNull();
expect(comp.mailerrorDiagnostic).toBeNull();
});

it('#login should call endpoint and return it's result', (done) => {
backend.connections.subscribe((connection: MockConnection) => {
const options = new ResponseOptions({
body: JSON.stringify({ success: true })
});
connection.mockRespond(new Response(options));

// Check the request method
expect(connection.request.method).toEqual(RequestMethod.Post);
// Check the url
expect(connection.request.url).toEqual('/auth/login');
// Check the body
// expect(connection.request.text())
expect(connection.request.text()).toEqual(JSON.stringify({ username: 'admin', password: 'admin' }));
// Check the request headers
expect(connection.request.headers.get('Content-Type')).toEqual('application/json');
});

loginService.login('admin', 'admin')
.subscribe((response) => {
console.log('response values are ---####------------ ', response);
// Check the response
expect(response.user.username).toEqual('admin');
expect(response.user.password).toEqual('admin');
// set value in sessionStorage
sessionStorage.setItem('currentUser', JSON.stringify(response));
sessionStorage.setItem('token', JSON.stringify(response.token));
sessionStorage.setItem('dismissOrders', 'false');

done();
},
(error) => {
expect(error).toThrowError();
});
});

});


the main problem is before executing the above file . The other spec file are executed



Thanks,
Kishan










share|improve this question
















When running the test case using jasmine/karma test cases. I am facing n issue which is before starting with the Login spec test case the other spec files are all called before completing the Login. It need to happen in an orderly manner which is like



1.Login

2.Dashboard

3.Order

etc.



Is there a way to do this.



login.spec.ts file



import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule, Router } from '@angular/router';
import { LoginComponent } from './login.component';
import { DebugElement } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule, By } from '@angular/platform-browser';
import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
import { RouterTestingModule } from '@angular/router/testing';
import { APP_BASE_HREF } from '@angular/common';
import { LoginService } from './login.service';
import { HttpClientModule } from '@angular/common/http';
import { ApiService } from '../config/api.service';
import { ConfigService } from '../config/config.service';
import { Constants } from '../config/Constant';
import { SharedService } from '../shared/shared.service';
import { Http, BaseRequestOptions, ResponseOptions, Response, RequestMethod } from '@angular/http';
import { inject } from '@angular/core/testing';
import { MockBackend, MockConnection } from '@angular/http/testing';

describe('LoginComponent', () => {
let comp: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
let de: DebugElement;
let el: HTMLElement;
let userNameEl: DebugElement;
let passwordEl: DebugElement;
let submitEl: DebugElement;
let loginService: LoginService = null;
let backend: MockBackend = null;

TestBed.overrideComponent(LoginComponent, {
set: {
providers: [
{
provide: LoginService,
useValue: loginService
},
{
provide: Router,
useClass: class { navigate = jasmine.createSpy('navigate'); }
}
]
}
});


beforeEach(async(() => {
// loginService = loginService;
// backend = mockBackend;
TestBed.configureTestingModule({
declarations: [
LoginComponent
],
imports: [
RouterModule.forRoot([{
path: '',
component: LoginComponent
}]),
BrowserModule,
FormsModule,
ReactiveFormsModule,
Ng2Bs3ModalModule,
RouterTestingModule,
HttpClientModule
],
providers: [
MockBackend,
BaseRequestOptions,
{
provide: Http,
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backendInstance, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
LoginService,
ApiService,
ConfigService,
Constants,
SharedService,
{ provide: APP_BASE_HREF, useValue: '/' }
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(LoginComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('form'));
el = de.nativeElement;
userNameEl = fixture.debugElement.query(By.css('input[id=InputEmail1]'));
passwordEl = fixture.debugElement.query(By.css('input[id=InputPassword1]'));
submitEl = fixture.debugElement.query(By.css('.login-btn'));
});
}));

beforeEach(inject([LoginService, MockBackend], (Service: LoginService, mockBackend: MockBackend) => {
loginService = Service;
backend = mockBackend;
}));


it('should create', () => {
expect(comp).toBeTruthy();
});

it('To check the initial value', () => {
expect(comp.submitted).toBe(false);
expect(comp.spinnerlogo).toBeFalsy();
expect(comp.data).toEqual({});
});

it(`entering value in username and password input controls`, () => {
userNameEl.nativeElement.value = 'admin';
passwordEl.nativeElement.value = 'admin';
fixture.detectChanges();
});

it('after entering value the button should enabled and click Action should happen', () => {
expect(submitEl.nativeElement.disabled).toBeFalsy();
const loginButtonSpy = spyOn(comp, 'onSubmit');
submitEl.triggerEventHandler('click', null);
expect(loginButtonSpy).toHaveBeenCalled();
});

it('calling onSubmit method after clicked the login button', () => {
comp.submitted = true;
comp.spinnerlogo = true;
comp.errorDiagnostic = null;
comp.mailerrorDiagnostic = null;
expect(comp.submitted).toBeTruthy();
expect(comp.spinnerlogo).toBeTruthy();
expect(comp.errorDiagnostic).toBeNull();
expect(comp.mailerrorDiagnostic).toBeNull();
});

it('#login should call endpoint and return it's result', (done) => {
backend.connections.subscribe((connection: MockConnection) => {
const options = new ResponseOptions({
body: JSON.stringify({ success: true })
});
connection.mockRespond(new Response(options));

// Check the request method
expect(connection.request.method).toEqual(RequestMethod.Post);
// Check the url
expect(connection.request.url).toEqual('/auth/login');
// Check the body
// expect(connection.request.text())
expect(connection.request.text()).toEqual(JSON.stringify({ username: 'admin', password: 'admin' }));
// Check the request headers
expect(connection.request.headers.get('Content-Type')).toEqual('application/json');
});

loginService.login('admin', 'admin')
.subscribe((response) => {
console.log('response values are ---####------------ ', response);
// Check the response
expect(response.user.username).toEqual('admin');
expect(response.user.password).toEqual('admin');
// set value in sessionStorage
sessionStorage.setItem('currentUser', JSON.stringify(response));
sessionStorage.setItem('token', JSON.stringify(response.token));
sessionStorage.setItem('dismissOrders', 'false');

done();
},
(error) => {
expect(error).toThrowError();
});
});

});


the main problem is before executing the above file . The other spec file are executed



Thanks,
Kishan







unit-testing angular5 karma-jasmine






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:05







Kishan Jr

















asked Nov 19 '18 at 12:31









Kishan JrKishan Jr

97




97













  • Please post your code

    – auburg
    Nov 19 '18 at 12:41











  • I have posted the login component spec file. This login spec file should run and after that it should move to dashboard but before running the login the another component spec files are running.

    – Kishan Jr
    Nov 19 '18 at 13:08











  • Are you not mocking the login component in your other component spec files ? Your other spec files shouldn't need to do any login so you wouldn't have this problem of having to run things in a certain order (order shouldn't matter and you have no control over that anyway).

    – auburg
    Nov 19 '18 at 13:12











  • so basically you are saying if I need any login response for getting access token, I need to perform mocklogin in every spec file and set localstorage for it

    – Kishan Jr
    Nov 19 '18 at 13:17











  • Pretty much - you shouldn't be testing login in your other components. Presumably your other components have the loginservice injected as a constructor parameter so it can be mocked out.

    – auburg
    Nov 19 '18 at 13:20





















  • Please post your code

    – auburg
    Nov 19 '18 at 12:41











  • I have posted the login component spec file. This login spec file should run and after that it should move to dashboard but before running the login the another component spec files are running.

    – Kishan Jr
    Nov 19 '18 at 13:08











  • Are you not mocking the login component in your other component spec files ? Your other spec files shouldn't need to do any login so you wouldn't have this problem of having to run things in a certain order (order shouldn't matter and you have no control over that anyway).

    – auburg
    Nov 19 '18 at 13:12











  • so basically you are saying if I need any login response for getting access token, I need to perform mocklogin in every spec file and set localstorage for it

    – Kishan Jr
    Nov 19 '18 at 13:17











  • Pretty much - you shouldn't be testing login in your other components. Presumably your other components have the loginservice injected as a constructor parameter so it can be mocked out.

    – auburg
    Nov 19 '18 at 13:20



















Please post your code

– auburg
Nov 19 '18 at 12:41





Please post your code

– auburg
Nov 19 '18 at 12:41













I have posted the login component spec file. This login spec file should run and after that it should move to dashboard but before running the login the another component spec files are running.

– Kishan Jr
Nov 19 '18 at 13:08





I have posted the login component spec file. This login spec file should run and after that it should move to dashboard but before running the login the another component spec files are running.

– Kishan Jr
Nov 19 '18 at 13:08













Are you not mocking the login component in your other component spec files ? Your other spec files shouldn't need to do any login so you wouldn't have this problem of having to run things in a certain order (order shouldn't matter and you have no control over that anyway).

– auburg
Nov 19 '18 at 13:12





Are you not mocking the login component in your other component spec files ? Your other spec files shouldn't need to do any login so you wouldn't have this problem of having to run things in a certain order (order shouldn't matter and you have no control over that anyway).

– auburg
Nov 19 '18 at 13:12













so basically you are saying if I need any login response for getting access token, I need to perform mocklogin in every spec file and set localstorage for it

– Kishan Jr
Nov 19 '18 at 13:17





so basically you are saying if I need any login response for getting access token, I need to perform mocklogin in every spec file and set localstorage for it

– Kishan Jr
Nov 19 '18 at 13:17













Pretty much - you shouldn't be testing login in your other components. Presumably your other components have the loginservice injected as a constructor parameter so it can be mocked out.

– auburg
Nov 19 '18 at 13:20







Pretty much - you shouldn't be testing login in your other components. Presumably your other components have the loginservice injected as a constructor parameter so it can be mocked out.

– auburg
Nov 19 '18 at 13:20














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374735%2fjasmine-karma-test-case-are-not-running-in-an-orderly-manner-using-angular5%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374735%2fjasmine-karma-test-case-are-not-running-in-an-orderly-manner-using-angular5%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?