Skip to content

Commit 4693876

Browse files
committed
Adds a unit test.
1 parent d9221eb commit 4693876

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
import fetchMock from "jest-fetch-mock";
3+
import {RestTemplate} from '../../../src/http/client';
4+
5+
describe("passport control", () => {
6+
7+
let template: RestTemplate;
8+
9+
beforeAll(() => {
10+
fetchMock.enableMocks();
11+
12+
template = new RestTemplate();
13+
});
14+
15+
it("should handle error correctly", async () => {
16+
// Arrange
17+
template.errorHandler = {
18+
hasError: () => true,
19+
handleError: () => {throw Error('')}
20+
}
21+
fetchMock.mockIf('https://localhost', req => {
22+
return Promise.resolve({
23+
status: 500,
24+
body: JSON.stringify({message: 'Error'}),
25+
headers: {
26+
'content-type': 'application/json'
27+
}
28+
});
29+
});
30+
31+
// Act
32+
let result: any = undefined;
33+
34+
try {
35+
await template.exchange('https://localhost', 'GET');
36+
} catch(error) {
37+
result = 'error'
38+
}
39+
40+
// Assert
41+
expect(result).toEqual('error');
42+
});
43+
44+
});

0 commit comments

Comments
 (0)