-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathauth-service.spec.ts
59 lines (47 loc) · 1.42 KB
/
auth-service.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
import { inject, TestBed } from '@angular/core/testing';
import { Subject } from 'rxjs/Subject';
import { AuthProviders, FirebaseAuth, FirebaseAuthState } from 'angularfire2';
import { AuthService } from './auth-service';
const fbAuthMethods = [
'subscribe'
// ... etc
];
describe('auth/', () => {
describe('AuthService', () => {
let authService;
let authSubject;
let mockFirebaseAuth;
beforeEach(() => {
authSubject = new Subject<FirebaseAuthState>();
mockFirebaseAuth = jasmine.createSpyObj('fbAuth', fbAuthMethods);
mockFirebaseAuth.subscribe.and.callFake(callback => {
authSubject.subscribe(callback);
});
TestBed.configureTestingModule({
providers: [
{provide: FirebaseAuth, useValue: mockFirebaseAuth},
AuthService
]
});
inject([AuthService], (service: AuthService) => {
authService = service;
})();
});
it('should be defined', () => {
expect(authService).toBeDefined();
});
it('should subscribe to auth state changes', () => {
expect(authService.authState).toBe(null);
let authData = {
uid: '12345',
provider: AuthProviders.Github,
auth: {
displayName: 'John Doe',
providerId: 'github.com'
}
} as FirebaseAuthState;
authSubject.next(authData);
expect(authService.authState).toBe(authData);
});
});
});