-
Notifications
You must be signed in to change notification settings - Fork 6
/
login-page.component.spec.ts
executable file
·67 lines (56 loc) · 2.26 KB
/
login-page.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { MatInputModule, MatCardModule } from '@angular/material';
import { ReactiveFormsModule } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NgxsModule, Store } from '@ngxs/store';
import { LoginPageComponent } from './login-page.component';
import { LoginFormComponent } from '../components/login-form.component';
import { AuthStates, Login } from '../store';
import { AuthService } from '../services/auth.service';
describe('Login Page', () => {
let fixture: ComponentFixture<LoginPageComponent>;
let store: Store;
let instance: LoginPageComponent;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
NgxsModule.forRoot(AuthStates),
MatInputModule,
MatCardModule,
ReactiveFormsModule,
],
declarations: [LoginPageComponent, LoginFormComponent],
providers: [AuthService],
});
fixture = TestBed.createComponent(LoginPageComponent);
instance = fixture.componentInstance;
store = TestBed.get(Store);
spyOn(store, 'dispatch').and.callThrough();
});
/**
* Container components are used as integration points for connecting
* the store to presentational components and dispatching
* actions to the store.
*
* Container methods that dispatch events are like a component's output observables.
* Container properties that select state from store are like a component's input properties.
* If pure components are functions of their inputs, containers are functions of state
*
* Traditionally you would query the components rendered template
* to validate its state. Since the components are analogous to
* pure functions, we take snapshots of these components for a given state
* to validate the rendered output and verify the component's output
* against changes in state.
*/
it('should compile', () => {
fixture.detectChanges();
expect(fixture).toMatchSnapshot();
});
it('should dispatch a login event on submit', () => {
const $event: any = {};
const action = new Login($event);
instance.onSubmit($event);
expect(store.dispatch).toHaveBeenCalledWith(action);
});
});