Slide 30
Slide 30 text
it('should load todos', waitForAsync(() => {
// arrange
const response = [ /* ...*/ ];
const getSpy = jest
.spyOn(httpClient, 'get')
.mockReturnValue(of(response));
// act
const result$ = service.loadTodos();
// assert
result$.subscribe((result) => {
expect(result).toEqual(response);
});
}));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
it('should load todos', waitForAsync(() => {
}));
1
// arrange
2
const response = [ /* ...*/ ];
3
const getSpy = jest
4
.spyOn(httpClient, 'get')
5
.mockReturnValue(of(response));
6
7
// act
8
const result$ = service.loadTodos();
9
10
// assert
11
result$.subscribe((result) => {
12
expect(result).toEqual(response);
13
});
14
15
it('should load todos', waitForAsync(() => {
// arrange
const response = [ /* ...*/ ];
const getSpy = jest
.spyOn(httpClient, 'get')
.mockReturnValue(of(response));
// act
const result$ = service.loadTodos();
// assert
result$.subscribe((result) => {
expect(result).toEqual(response);
});
}));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Testing Example - Async