Skip to content
Snippets Groups Projects
Commit eac2a216 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Tests on core containers => DONE

parent 87bb32d1
No related branches found
No related tags found
2 merge requests!147Develop,!135Resolve "Continue tests integration"
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { Component, Input } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import * as fromLogin from '../../login/store/login.reducer';
import * as loginActions from '../../login/store/login.action';
import { LoginToken } from "../../login/store/model";
describe('[Search] Container: AppComponent', () => {
@Component({ selector: 'app-nav', template: '' })
class NavStubComponent {
@Input() isAuthenticated: boolean;
@Input() loginToken: LoginToken;
}
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let store: MockStore;
const initialState = {
login: { ...fromLogin.initialState }
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [
AppComponent,
NavStubComponent
],
providers: [
provideMockStore({ initialState })
]
});
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should execute ngOnInit lifecycle', () => {
const loginLocalStorageAction = new loginActions.LoginLocalStorageAction();
const spy = spyOn(store, 'dispatch');
component.ngOnInit();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(loginLocalStorageAction);
});
it('#logout() should dispatch LogoutAction', () => {
const logoutAction = new loginActions.LogoutAction();
const spy = spyOn(store, 'dispatch');
component.logout();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(logoutAction);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment