-
Notifications
You must be signed in to change notification settings - Fork 9
/
component.spec.ts
43 lines (35 loc) · 1.17 KB
/
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
import { Component, User } from './component';
const mockData: User = { id: 'foo', name: 'bar', age: 40 };
describe('Component', () => {
let component: Component;
beforeEach(() => {
component = new Component();
component.setUser(mockData);
});
it('should return age as undefined if no user', () => {
expect(component.age).toBeUndefined();
});
it('should correctly identify the user age', () => {
expect(component.age).toEqual(mockData.age);
});
it('should increment the age of the user', () => {
component.incrementAge();
expect(component.age).toEqual(41);
});
it('should throw on increment age if user is undefined', () => {
expect(() => {
component.setUser(void 0);
component.incrementAge();
}).toThrow();
});
it('should decrement the age of the user', () => {
component.decrementAge();
expect(component.age).toEqual(39);
});
it('should throw on decrement age if user is undefined', () => {
expect(() => {
component.setUser(void 0);
component.decrementAge();
}).toThrow();
});
});