-
Notifications
You must be signed in to change notification settings - Fork 1
/
register.component.spec.ts
80 lines (73 loc) · 2.54 KB
/
register.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
68
69
70
71
72
73
74
75
76
77
78
79
80
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { of } from 'rxjs';
import { AuthenticationService } from '@services/authentication/authentication.service';
import { LayoutService } from '@services/layout/layout.service';
import { RegisterComponent } from './register.component';
describe('RegisterComponent', () => {
let component: RegisterComponent;
let fixture: ComponentFixture<RegisterComponent>;
const user = {
user: 'James',
password: '123456',
status: 'Single',
age: 18
};
const authenticationServiceMock = {
register: jasmine.createSpy('register').and.returnValue(of(user))
};
const ngbActiveModalMock = {
close: jasmine.createSpy('close')
};
const layoutServiceMock = {
setSharedData: jasmine.createSpy('setSharedData')
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormsModule
],
declarations: [
RegisterComponent
],
providers: [
{
provide: AuthenticationService,
useValue: authenticationServiceMock
},
{
provide: NgbActiveModal,
useValue: ngbActiveModalMock
},
{
provide: LayoutService,
useValue: layoutServiceMock
}
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RegisterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should not call register service when data is not complete', () => {
authenticationServiceMock.register.calls.reset();
component.register();
expect(authenticationServiceMock.register).not.toHaveBeenCalled();
});
it('should call register service when data is complete and valid', () => {
component.model = user;
component.register();
expect(authenticationServiceMock.register).toHaveBeenCalledWith(user);
expect(layoutServiceMock.setSharedData).toHaveBeenCalledWith({
isLoggedIn: true,
user
});
expect(ngbActiveModalMock.close).toHaveBeenCalled();
});
});